Jenkins creates maven project

Posted by ale1981 on Sun, 20 Feb 2022 18:19:01 +0100

1. Introduction to maven

https://mirrors.tuna.tsinghua.edu.cn/apache/maven/

2. Install mvn

# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
# cd /data/
# wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz
# tar xvf apache-maven-3.6.1-bin.tar.gz
# mv apache-maven-3.6.1 /usr/local/
# cd /usr/local/
# ln -s /usr/local/apache-maven-3.6.1/ /usr/local/maven
# /usr/local/maven/bin/mvn -v
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /usr/local/maven
Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_211-amd64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.el7.x86_64", arch: "amd64", family: "unix"

Configure maven
Edit the / etc/profile file, add parameters at the end, and add the maven command to the system environment variable

# vim /etc/profile
export PATH=/usr/local/maven/bin/:$PATH

# source /etc/profile
# mvn -v
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /usr/local/maven
Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_211-amd64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.el7.x86_64", arch: "amd64", family: "unix"

###Know maven installation directory
After installation. Maven's installation directory structure is as follows:

  • bin: this directory contains scripts run by mvn. These scripts are used to configure Java commands, prepare classpath and related java system properties, and then execute Java commands. Where mvn is a script based on UNIX platform, mvn Bat is a script based on Windows platform.
  • boot: this directory contains only one file, which is a class loader framework that Maven uses to load his own class library.
  • Conf: this directory contains a very important file settings xml. Used to globally define Maven's behavior. You can also copy the file to ~ / m2 / directory, customize Maven behavior within the user scope.
  • Lib: this directory contains all the java class libraries required by Maven runtime.

3. Jenkins builds a maven project

First, configure the path information of maven in the global configuration of the administrator

Add maven

Then install the plug-in Maven Integration online

After installation. When creating a new project, there will be one more option to build maven project

https://www.yiibai.com/maven
Using mvn command to build a java project Hello World failed the test command

# mvn archetype:generate -DgroupId=com.companyname.bank  -DartifactId=hello-world  -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

You'd better download it online
https://down.51cto.com/data/2462845
The directory structure after decompression is as follows

The commonly used maven commands need to be networked temporarily
The Mvn clean command is used to clean up the temporary files produced by the project, usually the target directory under the module
The Mvn test command is used for testing and executing test cases under src/test/java /. Use - dmaven test. Skip = true parameter can skip the test.
Generate target directory. But no jar or war package is generated in the directory

The Mvn package command is used for project packaging. It will generate jar or war files in the target directory under the module

The Mvn install command is used for module installation. Copy the packaged jar/war file to your local warehouse for use by other modules

Topics: Java Linux jenkins Maven