During the development process, some development kits in the company are sometimes used. Obviously, it is inappropriate to put these packages outside the company. In addition, because the project is under development, these internal dependencies may be constantly updated. You can build Maven servers within the company to centrally manage third-party and internal dependencies.
Here, we use nexus to build a local Maven server. The process is relatively simple.
1. Install the server
1. Download
On the official website of nexus, we can find the related Introduction: Ghost. I downloaded: nexus-oss-webapp-1.8.0-bundle.tar.gz. For details about how to use nexus, refer to repository management with nexus.
2. Installation
Decompress the downloaded file:
# Tar xzvf nexus-oss-webapp-1.8.0-bundle.tar.gz
After decompression, two folders are displayed in the same level Directory: nexus-oss-webapp-1.8.0 and sonatype-work. The former contains the running environment and Applications of nexus, and the latter contains your own configuration and data.
3. Start nexus
As mentioned above, the running environment of nexus is in the nexus-oss-webapp-1.8.0 directory, and the following goes to this directory to start:
# Cd nexus-oss-webapp-1.8.0/bin/JSW/linux-x86-64/
The directory contains a folder and three files: Lib, Nexus, platform, and wrapper. nexus is the startup command.
#./Nexus
Run the preceding command to get the usage prompt of the nexus command: Start command, Stop command stop. Start nexus below:
#./Nexus start
Starting nexus OSS...
Started nexus OSS
From the console output, we can see that the nexus has been successfully started. We can view more detailed information through the log file:
# Cd ~ /Nexus-oss-webapp-1.8.0/log
# Tail-F wrapper. Log
In the log, we can see that the default listening port of nexus is 8081. Then we can access: http: // host: 8081/nexus in the browser,
2. Configure nexus
Since the new nexus environment is only an empty repository, the first step is to synchronize with the remote Maven central repository.
If the repository is not synchronized to the remote repository after the reindex, you can check the settings of Each repository. Below are the settings for Maven central:
3. Use private servers in projects
After completing the above configuration, you can switch the default repository in the project to a local private server. You only need to add the repositories in POM. xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.maven.demo</groupId> <artifactId>MavenDemo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>MavenDemo</name> <url>http://maven.apache.org</url> <repositories> <repository> <snapshots> <enabled>true</enabled> </snapshots> <id>public</id> <name>Public Repositories</name> <url>http://172.28.189.138:8081/nexus/content/groups/public/</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>public</id> <name>Public Repositories</name> <url>http://172.28.189.138:8081/nexus/content/groups/public/</url> </pluginRepository> </pluginRepositories> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <type>jar</type> <scope>compile</scope> </dependency> </dependencies> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> </project>
After saving Pom. XML, you can go back to the nexus management interface and see that JUnit has been downloaded to the local nexus server.