私服的操作方法"/>
上传jar包依赖到maven私服的操作方法
1、配置maven的settings文件
<servers>
<server>
<id>releases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>snapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>
其中id对应着nexus私服的仓库id,如果要上传到其它仓库,同样需要在settings文件中进行相关配置即可。
用户名和密码对应nexus中设置的用户名密码,在Security->Users中,在对应的用户名上右键-> Set Password进行设置。
2、修改仓库权限
需要将对应的仓库权限改成Allow Redeploy,点击仓库名->Configuration
3、配置pom.xml文件
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://127.0.0.1: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://127.0.0.1:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
<id>releases</id>
<name>User Project Release</name>
<url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>User Project SNAPSHOTS</name>
<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
4、上传jar包命令
mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=jdbc14 -Dversion=1.0.0 -Dpackaging=jar -Dfile=C:\Users\wangc\.m2\repository\mysql\mysql-conn
ector-java\5.1.42\mysql-connector-java-5.1.42.jar -Durl=http://127.0.0.1:8081/nexus/content/repositories/releases/ -DrepositoryId=releases -X
其中DgroupId和DartifactId构成了该jar包在pom.xml的坐标,项目就是依靠这两个属性定位。
Dfile表示需要上传的jar包的绝对路径。
Durl私服上仓库的位置,打开nexus->repositories菜单,可以看到该路径。
DrepositoryId表示仓库id,在nexus的配置信息中可以找到。
-X表示输出全部日志,如果有报错可以看到详细的报错信息
注意:如果报错Cannot deploy artifact from the local repository,是因为要安装的jar和pom不能是位于本地repository的目录下,将要安装的jar和pom copy到其它目录再安装。
除了可以上传jar包之外,还可以pom
mvn deploy:deploy-file -Dfile=[your file] -DgroupId=[xxxx] -DartifactId=[xxxx] -Dversion=[xxxx] -Dpackaging=[pom|jar|other] -DrepositoryId=[id] -Durl=[repo url]
更多推荐
上传jar包依赖到maven私服的操作方法
发布评论