Why Maven private server?
In actual development, third-party jar s and internal communication service interfaces that may be used in the project will be entered into the company's private server.
From the actual development of the project:
-
Some components that cannot be downloaded from external warehouses, such as internal projects, can also be deployed to private servers for use by other dependent projects.
-
In order to save bandwidth and time, a private warehouse server is set up in the LAN to proxy all external remote warehouses. When the local Maven project needs to download components, first go to the private server for request. If the private server does not exist, then go to the remote warehouse for request. After downloading components from the remote warehouse, cache the components on the private server. In this way, there is no Internet link in time. Because the private server has cached a large number of components, the whole project can still be used normally. At the same time, it also reduces the compliance of the central warehouse.
The above is excerpted from the private server erection, and the detailed steps are as follows:
1. Download an image of nexus 3
docker pull sonatype/nexus3
2. Mount / var / nexus data inside the container to the host / root / nexus data directory
docker run -d -p 8081:8081 --name nexus -v /root/nexus-data:/var/nexus-data --restart=always sonatype/nexus3
Check the container startup through docker ps -a
Verify, view the details of the container through the id, and output the following ip address.
docker inspect container id
Then visit the following address and try it: curl 127.17.0.2:8081
If startup fails, close the firewall and try again:
systemctl stop firewalld.service
ok, visit the browser after startup http://ip:8081
So far, the private server has been built successfully.
Default login account admin admin123
Note that you may encounter the following errors at this time:
Incorrect username or password, or no permission to use the application.
When logging in to maven private server, the clear text password cannot be used by default. The ciphertext password should be used. It is generally in the directory where you create the container, such as root/nexus-data/admin.password , Note that you need to enter the container to find it. See the following instructions and figure:
docker exec -it c2101070de57 bash bash-4.2$ cd /nexus-data/ bash-4.2$ cat admin.password d62fa667-a22b-41db-a14a-6aa6f793f4fbbash-4.2$
Remove the back bash-4.2$,d62fa667-a22b-41db-a14a-6aa6f793f4fb This is the password.
After logging in again, you will be prompted to reset your password:
3. Create maven warehouse
Before uploading maven private server, let's create a warehouse
Select maven2 (hosted)
Fill in warehouse information:
Create user:
Fill in basic information
After creating the account, you can switch the account in the upper right corner.
Next, configure the local Maven > conf, find the setting.xml file under your local maven conf, and add the following information:
Note that under the services node:
<services> <server> <id>ttyy</id> <username>ttyy</username> <password>ttyy</password> </server> </services>
4. How to upload rack package to maven private server
Create a common maven project and configure pom.xml as follows:
<!--Note that the limited version must be RELEASE,Because the storage type of the uploaded corresponding warehouse is RELEASE --> <!--Specify warehouse address --> <distributionManagement> <repository> <!--This name is to be combined with.m2/settings.xml Set in ID agreement --> <id>ttyy</id> <url>http://192.168.10.130:8081/repository/ttyy-release/</url> </repository> </distributionManagement> <build> <plugins> <!--Release code Jar plug-in unit --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.7</version> </plugin> <!--Publish source code plug-ins --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Execute the following commands in the project command line:
mvn deploy
How to search after successful publishing? As shown below:
How to use it after release? I'm sure many small partners have used alicloud's private servers for the same reason:
<dependencies> <dependency> <groupId>club.sscai</groupId> <artifactId>ttyy-springboot</artifactId> <version>1.0-RELEASE</version> </dependency> </dependencies> <repositories> <repository> <id>ttyy</id> <url>http://192.168.10.130:8081/repository/ttyy-release/</url> </repository> </repositories>
java official account official account is set up to record my learning path. Interested buddy can pay attention to WeChat public address: niceyoo