您的位置:首页 > 运维架构 > Linux

【Linux运维入门】Maven将项目部署到Nexus

2016-02-17 23:15 701 查看
通过Maven的deploy命令,可以将项目的jar包部署到Nexus上,其他项目如果依赖该项目的jar包。就可以直接在pom.xml文件中配置上坐标即可。

下面来看看,如何将项目的jar包部署到Nexus上。

1、 首先要保证maven的settings.xml文件已经配置好了Nexus

可以参照下列文件进行配置

<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"> 
<localRepository>D:/Program Files/maven/repository</localRepository>

<!--私服的验证信息-->
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>

<!--maven对全部仓库的访问全部拦截到私服的public仓库中去,如果私服关闭,那么久不能访问中央工厂了-->
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<name>Local Repository</name>
<url>http://192.168.21.35:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<!--配置仓库的一些信息,其主要作用是用来覆写central中央仓库的一些配置信息-->
<profiles>
<profile>
<id>central</id>
<repositories>
<repository>
<id>central</id>
<name>Central</name>
<!-- 该 url 没有意义,可以随便写,但必须有。 -->
<url>http://*</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>local private nexus</name>
<url>http://192.168.21.35:8081/nexus/content/groups/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<!--激活上面配置的仓库信息-->
<activeProfiles>
<activeProfile>central</activeProfile>
</activeProfiles>

</settings>


2、 使用Eclipse新建一个Maven项目,并修改项目中的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>com.tgb</groupId>
<artifactId>itoo-test</artifactId>
<version>0.0.2-SNAPSHOT</version>

<!-- 项目部署到私服配置 -->
<distributionManagement> <!-- 远程部署管理信息 -->
<repository> <!--部署项目产生的构件到远程仓库需要的信息 -->
<id>releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.21.35:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository> <!-- 如果没有配置该元素,默认部署到repository元素配置的仓库 -->
<id>snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.21.35:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<!--end -->

</project>


3、 然后就可以使用deploy命令来部署了





4、 登陆Nexus查看部署情况



小结

通过这个操作就可以将咱们项目产生的jar包,war包统一交给Nexus来管理。其他项目可以通过配置构件的坐标,通过maven自动下载,添加依赖,使项目的jar包便于管理,提升了工作效率,不再需要拿着jar包拷来拷去。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  maven nexus 部署