“This article has participated in the good article call order activity, click to see: back end, big front end double track submission, 20,000 yuan prize pool for you to challenge!”
preface
The thing is that I recently took over a complex Java project. The unit-tested data for this project is a separate Web service. This service is invoked as Feign + microservice. The first step I took over was the need for additional unit tests, so I wrote unit tests for the project while improving the single test service.
At this point, you encounter the need to update the single test service toolkit and upload it to the company’s private server. The whole operation logic of EMM is relatively clear, but it is the first time to run it. Today, let’s see how to publish Jar packages to private servers.
Technical background
- Maven is a project management tool for building and dependency management of Java projects.
- Nexus is a powerful warehouse manager that greatly simplifies internal warehouse maintenance and access to external warehouses.
The following figure shows the corresponding functions of Nexus, and the picture is from the official website:
The project practice
1. Install the Nexus
If you have your own Nexus, you can skip this step.
I recommend using Docker installation, which is easy, easy, fast and cross-platform.
See Docker Hub for details
The shared directory is not specified. If the shared directory is specified, the data can be persisted
docker run -d -p 8081:8081 --name nexus3 --restart=always sonatype/nexus3
Copy the code
After the browser is started, go to http://localhost:8081. After the initialization is complete, you can perform subsequent operations.
Notes:
- if
http://localhost:8081/
404, try to accesshttp://localhost:8081/nexus
- The nexus initialization password needs to be obtained from the Docker container
docker exec nexus3 cat /nexus-data/admin.password
2. Configure the repository
- 2.1 To facilitate the management of new
Blob Stores
- 2.2 new
Repositories maven2(hosted)
Note the parameters in the figure below
- 2.3 new
Repositories maven2(proxy)
Note the parameters in the figure below
# Ali Cloud's Maven central warehouse address
http://maven.aliyun.com/nexus/content/groups/public/
Copy the code
- 2.4 new
Repositories maven2(group)
Note the parameters in the figure below
- 2.5 Viewing the Result and Copying the corresponding IP address
3. Configure the environment
- 3.1 configuration
.m2/settings.xml
.The address here is derived from the warehouse address in the previous step.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<name>nexus respository</name>
<url>http://deepin:8081/repository/test_group/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
Copy the code
- 3.2 Configuring a Local Project
pom.xml
.The address in this step must be the same as that in the previous step.
<! -... -->
Copy the code
</repository>
<snapshotRepository>
<id>nexus</id>
<name>nexus repository</name>
<url>http://deepin:8081/repository/test_hosted/</url>
</snapshotRepository>
Copy the code
4. Upload the Jar package
Local maven version informationApache Maven 3.6.3 $MVN - v (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: / usr /localCellar/maven/3.6.3_1/libexec Java version: 14.0.1, vendor: N/A, Runtime: /usr/local/ Cellar/its / 14.0.1 / libexec/its JDK/Contents/Home Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
Copy the code
- Method 1: Click in Idea
- Method two: Command line
Execute in the project directory
mvn deploy
Copy the code
View the running result:
5. Resolve the upload error
-
Return code is: 401 Usually indicates an account password. You need to check whether the account password is correctly configured. In addition, you need to pay attention to the configuration of POM. XML and settings. XML.
-
Return code is: 400 Nexus Repository has three types: Hosted, Proxy, and Group; You can only be deployed in a Hosted warehouse. You need to check the warehouse type configured.
-
Return code is: 405 Generally, there is a problem with the publishing address. Check the publishing address.
Here, the Group is used to package Hosted Hosted and Proxy together. One Jar package is used to manage the upload and one Jar package is used to manage the Proxy.
The following figure shows the uploaded Jar package:
The following is the Jar package downloaded after the agent:
6. Other
Because Nexus supports a variety of warehouse Settings, you can build your own Docker, Pypi and Npm warehouses in the future, and interested partners can study by themselves.
The resources
- The Maven global configuration file settings. XML is detailed