项目有些公共功能模块类似common,api等打成jar包,方便其它项目引入使用。
1,在自己要打成jar包的工程的pom文件里面加入公司的私库地址。(ps:记得你要打包的工程的pom文件里面不要加入其它私库没有的父模块,不然打包后,其它工程拉取不到,因为你的父工程不一定上传到私库了)。
<parent> <groupId>xxxx.xxxxxx</groupId> <artifactId>xxxxx-com-parent</artifactId> <version>2.7.0</version> </parent>
)
pom文件加入
<distributionManagement> <snapshotRepository> <id>maven-snapshots</id> <url>http://xxxxx:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
maven的setting.xml配置里面增加对应私库服务的用户名跟密码配置。
<server>
<id>maven-snapshots</id>
<username>xxxxxxx</username>
<password>xxxxxxx</password>
</server>
pom文件里面的 id配置maven-snapshots对应你maven setting.xml里面的 server下面的id。这样就可以在IDEAL里面找到对应要上传到私库的工程,点击deploy打包上传。
2,在另外工程里面引入时,在pom文件里面增加对应私库的地址。
<repositories> <repository> <!-- ID必填 --> <id>maven-snapshots</id> <!-- Maven私服SNAPSHAT仓库URL,这里需要替换为实际公司的私服地址 --> <url>http://xxxxxxx/repository/maven-snapshots</url> <!-- 设置启用SNAPSHOT --> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
如果此时拉取不到,在到maven的setting.xml里面去配置一下。
<profiles>
<!-- 阿里云配置: 提高国内的jar包下载速度 -->
<profile>
<id>aliyun-Repository</id>
<repositories>
<repository>
<id>aliyun</id>
<url>>http://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>maven-snapshot-Repository</id>
<repositories>
<repository>
<id>maven-snapshots</id>
<url>http://xxxxx:8081/repository/maven-snapshots</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>aliyun-Repository</activeProfile>
<!--<activeProfile>java-group-Repository</activeProfile>-->
<activeProfile>maven-snapshot-Repository</activeProfile>
</activeProfiles>
最终,在别的工程里面终于可以拉取到jar包了。