1.构建出包
mvn clean package
2.引用仓库配置
a.本地配置查找仓库
在settings.xml配置文件中增加内容
maven的配置信息,Windows系统的话,一般都在个人目录的.m2目录下。使用IDE可在IDE里单独指定,依具体IDE而定。
settings -》profiles-》repositories 节点下配置repository标签,也即maven仓库配置
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<id>iask</id>
<repositories>
<repository>
<id>test-release</id>
<url>http://localhost:8081/repository/test-release/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>test-snapshot</id>
<url>http://localhost:8081/repository/test-snapshot/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
b.工程配置查找仓库
在工程pom文件中配置
在project-》repositories 节点下配置repository标签,也即maven仓库配置
<?xml version="1.0" encoding="UTF-8"?>
<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">
<repositories>
<!-- 开源库,包括中央仓库、Apache等仓库,由RDM团队维护 -->
<repository>
<id>central-oa</id>
<url>http://maven.oa.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
3.发布仓库配置
<distributionManagement>
<repository>
<id>iask-release</id>
<name>Release Repository of iask</name>
<url>http://10.123.10.76:8081/repository/iask-release/</url>
</repository>
<snapshotRepository>
<id>iask-snapshot</id>
<name>Snapshot Repository of iask</name>
<url>http://10.123.10.76:8081/repository/iask-snapshot/</url>
</snapshotRepository>
</distributionManagement>
4.发布到maven仓库
a.工程发布
1)配置好发布仓库(参考第3点)
2)工程下执行 mvn clean deploy
b.jar包发布
mvn deploy:deploy-file -Dmaven.test.skip=true -Dfile=webp-imageio-1.0.jar -DgroupId=com.google.image -DartifactId=webp-imageio -Dversion=1.0 -Dpackaging=jar -DrepositoryId=test-release -Durl=http://localhost:8081/repository/test-release
如果出现错误
Cannot deploy artifact from the local repository XXX
由maven的安全机制导致,不能部署在本地repository的目录下的jar文件,可以拷贝出来到其他目录下再发布
5.强制刷新出包,带上-U参数,出包时强制到远程仓库检查缺少的包和
mvn clean package -U
网友评论