Maven+Nexus Environment for Java Packaging Environment Deployment

Maven+Nexus Environment for Java Packaging Environment Deployment

(1) Introduction to the Maven Project
For more information, please go to the official website:
We need to know Maven's main introductory information:
1.Maven is the next free open source project belonging to the apache Software Foundation and is a cross-platform project management tool.
2.Maven uses a concept called Project Object Model (POM) to manage projects, and all project configuration information is defined in a file called POM.xml.
3. Mainly serves the construction of Java platform, dependency management, project management.
4.Maven provides developers with a complete life cycle framework that uses standard directory structures and default life cycles.
5.POM.xml This file is used for management: source code, configuration files, developer information and roles, problem tracking system, organization information, project authorization, project url, project dependencies, etc.This file is maintained by development and can be taken care of by our maintenance staff.
As for Maven's powerful capabilities, we need to understand how Maven uses packaging for java projects; how to resolve dependencies in the packaging process for java projects; how to make dependency packages download faster and download packages slower because some packages are on foreign servers by default, and this document is built around this issue in the direction of maintenance.
Environmental preparation:    Jenkins    nexus / git
(2) Deploy Maven [just install it on the Jenkins server]
Official website:
Tsinghua Mirror:
1.Create package storage location
[root@jenkins ~]# mkdir /server/scripts/tools
[root@jenkins tools]# ll
//Total dosage 8296
-rw-r--r-- 1 root root 8491533 11 month 18 2015 apache-maven-3.3.9-bin.tar.gz
2.Unzip Package
[root@jenkins tools]# tar xf apache-maven-3.3.9-bin.tar.gz
3.Move software to common directories
[root@jenkins tools]# mv apache-maven-3.3.9 /usr/local/
bin/     games/   lib/     libexec/ share/   
etc/     include/ lib64/   sbin/    src/     
4.Remove version number for connection
[root@jenkins tools]# ln -s /usr/local/apache-maven-3.3.9/ /usr/local/maven
5.Set environment variables so that commands do not need to be found, package location
[root@jenkins tools]# echo "export PATH=/usr/local/maven/bin/:$PATH" >>/etc/profile
6.Test the command and view the version
[root@jenkins tools]# mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /usr/local/maven
Java version: 1.8.0_181, vendor: Oracle Corporation
Java home: /usr/java/jdk1.8.0_181-amd64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-229.el7.x86_64", arch: "amd64", family: "unix"
maven Common commands: 
[root@jenkins bin]# ll /usr/local/maven/bin/
//Total dosage 32
-rw-r--r-- 1 root root  230 11 month 11 2015 m2.conf
-rwxr-xr-x 1 root root 7383 11 month 11 2015 mvn
-rw-r--r-- 1 root root 6067 11 month 11 2015 mvn.cmd
-rwxr-xr-x 1 root root 1815 11 month 11 2015 mvnDebug
-rw-r--r-- 1 root root 1513 11 month 11 2015 mvnDebug.cmd
-rwxr-xr-x 1 root root 1843 11 month 11 2015 mvnyjp
(3) Packaging with maven
In some java projects, such as jar war packages, which are not packaged directly, tar packages are usually received and need to be packaged by operation and maintenance, then the following Maven packaging tool is used.
Parameters and instructions for maven:
package: package source code after compilation using jar format, download dependent packages in.m2
clean:: Clear the previous compilation, restore the original compilation environment, and clear the package when used
validate: Verify package integrity
Compile: compile project source
test: test compiled source code
install: install the package locally or as a good package to depend on for other projects
deploy: Deployment is done in an integrated or publishing environment, where the final package is copied to a remote storage repository and shared.
Mvn-v:: View the java maven and kernel information for the version
Packaging process:
1. Download the source package locally and decompress it within source
3.mvn package #What you need here is that the downloaded packages are slow abroad by default and need to be changed to domestic or set up private services.
Common naming:
[root@jenkins ~]# mvn package    #Packages typed this way are jar packages by default, maven's central repository download dependencies and plug-ins by default, which is slightly slower here because the visited foreign address pulls down the local one.You will need to adjust to private service later, if you have more java code
[root@jenkins ~]# mvn clean
[root@jenkins ~]# mvn test
[root@jenkins ~]# mvn install
[root@jenkins ~]# mvn -v         #View the java maven and kernel information for the version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /usr/local/maven
Java version: 1.8.0_181, vendor: Oracle Corporation
Java home: /usr/java/jdk1.8.0_181-amd64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-229.el7.x86_64", arch: "amd64", family: "unix"
[root@jenkins ~]# ll target/
-rw-r--r-- 1 root root 3430 2020-3-19 23:39 world-1.0-SNAPSHOT.jar    #This kind of jar package or war package can be published directly online for use.The default is to publish using the Tomcat environment.


(4) Deploy Maven Private Server nexus
Slow solution:
1. Build private clothing
2. Use Ali Cloud's source (java projects are not very common and can be used)
Private service is to solve the problem that download dependencies are slower to process when using Maven to package java because some packages go abroad by default in Maven's central warehouse and download slowly increases the packaging time.
[1] Configure Aliyun's Maven Central Warehouse and modify Maven's main configuration file to make it globally effective
1.Find Main Profile
[root@jenkins conf]# ll  /usr/local/maven/conf/settings.xml    #This is the main profile
 Total dosage 16
drwxr-xr-x 2 root root    36 11 month 11 2015 logging
-rw-r--r-- 1 root root 10216 11 month 11 2015 settings.xml
-rw-r--r-- 1 root root  3649 11 month 11 2015 toolchains.xml
2.Copy the original configuration file
[root@jenkins conf]# cp settings.xml settings.xml.bak
[root@jenkins conf]# ls
logging  settings.xml  settings.xml.bak  toolchains.xml
3.Modify profile in mirrors Add under label
Global validity:
[root@jenkins conf]# vim settings.xml


There is no need to restart the service after adding the configuration. Instead, you can go directly to the project and re-execute the mvn package for packaging, which will remove the missing packages and dependencies from Ali Source, and the results will be fast.
Configure screenshots of the appendix here to avoid confusion; configure

[2] Build default port 8081 for private nexus
Installation package download address:‐oss‐sonatype
The key points to note when configuring private services are:
1. Using the java environment
2. Effective Rules
Configuration in Maven's master profile, globally effective
(2) Configuration of pom.xml within the project source package is locally effective, that is, valid for the current project and invalid for other projects
Configuration on the nexus machine:
1.Upload packages for installation
[root@nexus tools]# ll
//Total dosage 286068
-rw-r--r-- 1 root root 170023183 3 month   8 18:47 jdk-8u181-linux-x64.rpm
-rw-r--r-- 1 root root 122904706 3 month   8 18:48 nexus-3.13.0-01-unix.tar.gz Environment Installation
[root@nexus tools]# rpm -ivh jdk-8u181-linux-x64.rpm
//Warning: jdk-8u181-linux-x64.rpm: head V3 RSA/SHA256 Signature, secret key ID ec551f03: NOKEY
   1:jdk1.8-2000:1.8.0_181-fcs        ################################# [100%]
Unpacking JAR files...
3.Installation Command
[root@nexus tools]# rpm ‐ivh jdk-8u181-linux-x64.rpm
[root@nexus tools]# tar xf nexus-3.13.0-01-unix.tar.gz
[root@nexus tools]# mv nexus‐3.13.001 /usr/local/
[root@nexus tools]# ln ‐s /usr/local/nexus‐3.13.001/ /usr/local/nexus
[root@nexus tools]# /usr/local/nexus/bin/nexus start        #Start Services
WARNING: ************************************************************
WARNING: Detected execution as "root" user.  This is NOT recommended!
WARNING: ************************************************************
Starting nexus   #Starting up
[root@nexus tools]# /usr/local/nexus/bin/nexus status
WARNING: ************************************************************
WARNING: Detected execution as "root" user.  This is NOT recommended!
WARNING: ************************************************************
nexus is running.  #Start Successful
4.Default port is 8081 
[root@nexus tools]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0  *               LISTEN      29575/java          
tcp        0      0*               LISTEN      29575/java          
tcp        0      0    *               LISTEN      1028/sshd           
tcp6       0      0 :::22                   :::*                    LISTEN      1028/sshd      


[3] Log on to the web interface
Default user: admin
Default password: admin123
<1>. View basic information
If the disk capacity is not enough, you can expand the hard disk and increase the capacity.
<2>.Change proxy service, transform proxy download path
<3>.Modify download link of central warehouse
Modifying the proxy is also downloaded on Ali Source. It is the same as the proxy address of the previous configuration Maven. So what is the difference from the previous configuration?It can be understood that this (private nexus) is equivalent to our commonly used yum source.
Original address:
The modified Aliyun address is:
<4>.Locate the private service address and add it to Maven's master profile to download java dependencies
<5>.Private service address is as follows, this address can be matched to Maven,
This implements that Maven+Private Serve nexus solves the packaging dependency of java.Every time Maven executes packaged Java code, after the first request to nexus, packages that are not available in local private service will go to Ali to download the cache locally and then be provided to Maven for use. In the future, packaged local owner will not go to Ali to download, and will use local dependent packages directly to solve the dependency relationship of Java packaging.See <6> this diagram for the order of requests.
<6>.Cache request dependency order
(5) Configure and integrate Maven+nexus private service
Because Jenkins and Maven On one host; nexus Another host wants to understand the environment.
integration nexus+Maven Configuration:
1. Log on to Maven Server, modify configuration settings.xml Main Profile
[root@jenkins conf]# pwd
[root@jenkins conf]# ll
 Total dosage 52
drwxr-xr-x 2 root root    36 11 month 11 2015 logging
-rw-r--r-- 1 root root 11620 3 month  19 11:43 settings.xml
-rw-r--r-- 1 root root 10399 3 month  19 07:32 settings.xml.ailiyun.bak
-rw-r--r-- 1 root root 11620 3 month  19 11:44 settings.xml.all
-rw-r--r-- 1 root root 10216 3 month  19 04:08 settings.xml.bak
-rw-r--r-- 1 root root  3649 11 month 11 2015 toolchains.xml
[root@jenkins conf]# vim settings.xml
 Add the following configuration to the main configuration file to complete the integration, and then you can achieve java Code packaging, through gitlib+Jenkins Automatically go online to web Site.
2. find<servers> Label, add nexus Default authentication information
3.find<mirrors>Label, add mirror
4.find<profiles>Label, add warehouse information:
5.find activeProfiles Activate warehouse
(6) Integrated view, if configuration is different, the configuration of reference (5) shall prevail
1. >Authentication Information
2. >nexus private service address
3. > Add warehouse configuration
4. >Activate the configuration warehouse

Tags: Linux Maven nexus Java jenkins

Posted on Thu, 19 Mar 2020 03:05:47 -0400 by Marsha