Why use private library
By default, maven goes to the remote central warehouse to download the JAR package. It's quite slow to visit the foreign network. If everyone in the team downloads the JAR package once, it's undoubtedly a waste of the network. Of course, it can also add the domestic image, such as Ali's, which is relatively stable. But if you want to add the JAR package that doesn't exist remotely, it's more troublesome.
So, to use private library, first, as long as one person has downloaded the open source package, other people do not need to download it again, just download it from private library. Second, it can be used to manage third-party company's or remote warehouse does not exist JAR package, or company does not open source JAR package.
Recommend domestic stable images, such as Alibaba's
http://maven.aliyun.com/nexus/content/groups/public/
nexus download and install
First, go to the official website of sonatype to download the nexus package. To download the OSS version of the open source free version, i.e. Open Source Software.
https://www.sonatype.com/nexus-repository-oss
Download the latest 3.X For example, Download windows.
After downloading, click the startup file in the bin directory. The default port is 8081, and the access path is /. You can also modify it in the configuration file. Here, the default is used.
After startup, open localhost:8081 , nexus default user name is admin/admin123
The following warehouses are installed by default. In the console, you can also modify the address of the remote warehouse and the third-party warehouse.
Maven configuration
Modify maven home directory conf/setting.xml Profile.
Add the user name and password configuration information for nexus authentication.
<servers> <server> <id>nexus-releases</id> <privateKey>admin</privateKey> <passphrase>admin123</passphrase> </server> <server> <id>nexus-snapshots</id> <privateKey>admin</privateKey> <passphrase>admin123</passphrase> </server> </servers>
Add mirror image
<mirrors> <mirror> <id>Nexus</id> <mirrorOf>*</mirrorOf> <name>Nexus</name> <url>http://127.0.0.1:8081/repository/maven-public/</url> </mirror> </mirrors>
Add private library
<profiles> <profile> <id>Nexus</id> <repositories> <repository> <id>Nexus</id> <name>Nexus</name> <url>http://127.0.0.1:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>Nexus</id> <name>Nexus</name> <url>http://127.0.0.1:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles>
Activate private library
<activeProfiles> <activeProfile>Nexus</activeProfile> </activeProfiles>
Publish to private library
Add in pom profile
<!-- nexus-releases nexus-snapshots And settings.xml in server Next id corresponding --> <distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Releases Repository</name> <url>http://localhost:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshots Repository</name> <url>http://localhost:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
On the project, the command mvn deploy can be used to package and publish to the private library.
Recommend to my blog to read more:
1.Java JVM, collection, multithreading, new features series
2.Spring MVC, Spring Boot, Spring Cloud series tutorials
3.Maven, Git, Eclipse, Intellij IDEA series tools tutorial
4.Latest interview questions of Java, backend, architecture, Alibaba and other large factories
Feel good, don't forget to like + forward!