I think back to the time when maven was not used before, we used the original project skeleton of eclipse When building a project, there is often a lib folder in the project directory to store the jar files required for the project. Every time a new project is built, there will be such a lib folder. Then copy the jar into the lib folder configuration path. Obviously there is a lot of repeated work, and the jar packages used in different projects are different, so we need to slowly distinguish them. Then we used project management tools such as svn or git, and we needed to introduce a large number of jar files into the code base, which was not very appropriate.
Maven can help us solve these problems. The maven warehouse is a location specifically used to store jar files (it can also be used to store project war, zip, pom and other files). Each jar file is assigned a coordinate in the maven warehouse, such as the jstl jar package:
<groupid>javax.servlet</groupid> 组ID <artifactid>jstl</artifactid> 构建ID ... 其余属性后续介绍
In this way, maven can easily control the project dependency version. Simply put, the maven warehouse helps us manage project components in a unified manner.
## The query path of project construction: first query the local warehouse, if not found, the central warehouse will be queried, if not found, an error will be reported. The central warehouse address is:
above. Three are more common and are used more often in projects. However, due to the slow download speed and incomplete jar files in the warehouse, actual enterprise development requires us to build a private server warehouse.
Click to download, password: 1ar1
3. Configure maven private server
. The initial account is admin and the password is admin123. It can be modified after successful login. You can find your account password yourself.
on the left.
Change the Download Remote Indexes property to True, and then click save. You can view it in the menu bar Scheduled Tasks The progress of downloading the index.
Add your own proxy remote library
, sometimes our project needs to introduce some special jar files, such as some jar packages of Jboss. At this time, we can also proxy the remote warehouse in the private server. :
Click add to add the proxy type, fill in the id, name and url in order. In this case,
Remote warehouse: 4.Use nexus to build a LAN private server的使用,上面提到的一些特殊的商业性质相关的jar文件,比如oracle的驱动包,ojdbc.jar并不支持远程下载,这时候可以将我们本地下载好的jar包上传到私服。 注意GAV设置要与你pom.xml中一致,上传后添加到Artifacts点击上传即可: 切记点击刷新,刷新后点击唯一的一个group仓库,点击配置Configuration就可以看到刚才我们手动添加的代理仓库,然后将代理仓库添加到组仓库,这样依赖,项目中之需要配置组仓库的url就可以访问多个私服仓库。 在上述步骤完成后,即可在项目中引用私服,pom.xml中改变默认下载仓库url: 指定插件仓库 配置好之后就可以从私服下载依赖包了。但是这种方式只能在改项目中起作用,每次配置项目都需要写两遍,为了将懒人模式进行到底,我们还可以指定全局的私有仓库。 找到maven文件的中的Use nexus to build a LAN private server文件 在Use nexus to build a LAN private server中添加配置:<repository>
<id>jboss</id>
<name>JBoss Repository</name>
<url>;/url>
<releases>
<updatepolicy>daily</updatepolicy><!-- never,always,interval n -->
<enabled>true</enabled>
<checksumpolicy>warn</checksumpolicy><!-- fail,ignore -->
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<layout>default</layout>
</url></repository>
5.由于私服仓库数量过多,导致配置复杂度提高,所以需要用到上述的group类型仓库:四. 局域网使用maven私服
4.1 单个项目使用maven私服
指定私服仓库,我的ip是170,不要全盘复制<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://192.168.1.170:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginrepositories>
<pluginrepository>
<id>nexus</id>
<name>nexus</name>
<url>http://192.168.1.170:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginrepository>
</pluginrepositories>
4.2 全局指定私服
在profiles
<profile> <repositories> <id>central</id> <name>central</name> <url>http://192.168.1.170:8081/nexus/content/groups/public/</url> <layout>default</layout> <releases> <enabled>true<enabled> </enabled></enabled></releases> <snapshots> <enabled>true<enabled> </enabled></enabled></snapshots> </repositories> </profile>
配置好之后激活profile
<activeprofiles> <activeprofile>central</activeprofile> </activeprofiles>
这样一来,这台电脑上所有maven项目下载jar文件时都会先访问局域网170的电脑。
-----------------------------------windows配置私服完毕-----------------------------------
扩展:setting,xml中各标签的意义:
servers(服务器)
<servers> <server> <id>server001</id> <username>my_login</username> <password>my_password</password> <privatekey>${usr.home}/.ssh/id_dsa</privatekey> <passphrase>some_passphrase</passphrase> <filepermissions>664</filepermissions> <directorypermissions>775</directorypermissions> <configuration></configuration> </server> </servers>
id与pom.xml中distributionManagement的id保持一致,服务器标识
username和password表示服务器认证需要的用户民和密码
privateKey, passphrase一组密钥 (不常用)
filePermissions, directoryPermissions如果在部署的时候会创建一个仓库文件或者目录,这时候就可以使用权限(不常用)
2.mirrors(镜像)
<mirrors> <mirror> <id>planetmirror.com</id> <name>PlanetMirror Australia</name> <url>;/url> <mirrorof>central</mirrorof> </url></mirror> </mirrors>
设置一个中央仓库的镜像,看仓库分类,也是远程仓库的一种配置方式。
3.profiles(构建环境)
这个可能比较难理解,maven权威指南一书中这样说:
Profile能让你为一个特殊的环境自定义一个特殊的构建;
构建环境的两个例子是产品环境和开发环境。当你在开发环境中工作时,你的系统可能被配置成访问运行在你本机的开发数据库实例,而在产品环境中,你的系统被配置成从产品数据库读取数据。Maven能让你定义任意数量的构建环境(构建profile),这些定义可以覆盖pom.xml中的任何配置。
简单理解就是你可以先profile中先构件好项目运行的环境,比如预设了A环境实在开发中使用,而实际上线是B环境,那么在上线的时候我们不需要一个个修改pom.xml中的配置,只需要激活改profile即可。
4.activation(激活构建环境 )
<activation> <activebydefault>false</activebydefault> <jdk>1.5</jdk> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> <property> <name>mavenVersion</name> <value>2.0.3</value> </property> </activation>
指定profile中配置的环境在什么时候开始生效
5.activeProfiles(激活了的profile)
<activeprofiles> <activeprofile>env-test</activeprofile> </activeprofiles>
在Use nexus to build a LAN private server最后的一个标签,表示env-test这个profile已被激活
The above is the detailed content of Use nexus to build a LAN private server. For more information, please follow other related articles on the PHP Chinese website!