Install maven in Linux environment and configuration of warehouse and domestic mirror

table of Contents

One, maven download

Two, maven install linux

2.1: Log in to the linux server with root privileges, enter the disk /usr/local/ directory, and put the downloaded maven package in the changed folder

2.2: Unzip the apache-maven-3.6.3-bin.tar.gz file

2.3: Configure maven's warehouse for storing jar packages and add Ali's domestic mirror address

2.4: Configure maven environment variables, edit vi /etc/profile file, and add maven environment configuration information at the end.

2.5: Reload the profile file

2.6: Test whether the installation is successful: mvn -v command, the following message appears, indicating that the maven installation is complete.

Third, the actual springboot project test package startup project

3.1 Upload the project to the Linux machine as follows, only the code has not been packaged

3.2 Package the project:


Apache Maven is a software project management tool we often use

One, maven download

Download link: https://maven.apache.org/download.cgi

Two, maven install linux

2.1: Log in to the linux server with root privileges, enter the disk /usr/local/ directory, and put the downloaded maven package in the changed folder

cd /usr/local/

2.2: Unzip the apache-maven-3.6.3-bin.tar.gz file

tar -zxvf apache-maven-3.6.3-bin.tar.gz

2.3: Configure maven's warehouse for storing jar packages and add Ali's domestic mirror address

2.3.1: Enter the apache-maven-3.6.3 directory and create a warehouse folder for storing files 

mkdir myrepository

2.3.2: Enter the config configuration directory of maven and edit the setting.xml configuration file.

cd conf/
vim settings.xml

2.3.3: Add the warehouse and mirror configuration respectively in the location shown in the following figure (the screenshot of the warehouse in the figure is just a reference directory, the specific configuration is added according to the warehouse directory created in step 2.3.1), save and exit

<!-- my repositroy-->
<localRepository>/usr/local/apache-maven-3.6.3/myrepository</localRepository>



<!-- aliyun-->
<mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
       <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
</mirror>

 

 

2.4: Configure maven environment variables, edit vi /etc/profile file, and add maven environment configuration information at the end.

vim /etc/profile
export MAVEN_HOME=/usr/local/apache-maven-3.6.3
export PATH=$PATH:$MAVEN_HOME/bin

2.5: Reload the profile file

source /etc/profile

2.6: Test whether the installation is successful: mvn -v command, the following message appears, indicating that the maven installation is complete.

[root@iZ2ze0xg0kwnf480rd6ekrZ conf]# mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/apache-maven-3.6.3
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_181/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-147.5.1.el8_1.x86_64", arch: "amd64", family: "unix"
[root@iZ2ze0xg0kwnf480rd6ekrZ conf]# 

At this point, the maven environment is all set up. The third step is for the blogger to test whether his cloud host can successfully run the springboot project. Interested students can continue to look down, and they need to have a java foundation.


Third, the actual springboot project test package startup project

Set up the java environment, create a springboot project yourself, ensure that the project can be executed successfully, and upload the project code to the maven server.

Those who are too lazy to build the project can clone directly: https://github.com/yangshilei/java-springboot-learn.git

If you don’t bother to clone, let’s change...

3.1 Upload the project to the Linux machine as follows, only the code has not been packaged

3.2 Package the project:

The first time you package, it will pull a lot of dependent packages, which will take a little longer, and you need to wait patiently

mvn package

As shown below, the project is successfully built...

3.3 Run the project, enter the target directory, and execute the project with java.

cd target/
java -jar learn-0.0.1-SNAPSHOT.jar

As shown in the figure, the project started successfully!

3.4 Interface test: Swagger code is configured in the project and tested directly with swagger.

Visit http://ip:7080/swagger-ui.html address, ip needs to be replaced with your own server ip to make sure your linux network is connected.

http://47.94.111.71:7080/swagger-ui.html

You can see that the code successfully printed multiple logs of calling the weather forecast interface.

So far all the demos are over.

 

Guess you like

Origin blog.csdn.net/qq_37488998/article/details/111683904