maven如何将jar包打包并上传到私有仓库呢?
下文笔者讲述maven中jar包打包并上传到私有仓库的方法及示例分享,如下所示
jar包打包上传至私有仓库的实现思路
1.项目的pom.xml中设置私有仓库的信息 2.Maven的settings.xml中设置私有仓库相应的账号和密码 3.pom.xml中设置相应的插件 4.运行 mvn package deploy 即可将jar包打包并上传到私有仓库中例
私有仓库nexus3安装在本机,对外的端口8088 http://localhost:8088/nexus3/repository/maven-releases http://localhost:8088/nexus3/repository/maven-snapshots例
一.pom.xml引入 如果发布到releases私库(与build标签平级放入) <distributionManagement> <repository> <id>releases</id> <url>http://localhost:8081/nexus3/repository/maven-releases/</url> </repository> </distributionManagement> 如果发布到snapshots私库(与build标签平级放入) <distributionManagement> <snapshotRepository> <id>snapshots</id> <url>http://localhost:8081/nexus3/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement> 二.Maven的settings.xml 在servers标签下增加如下配置,配置发布到私库的账号和密码(如nexus3的账号admin和密码admin123) <server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server> 三.pom.xml中添加源码插件 <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <!-- 编译插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <encoding>${project.build.sourceEncoding}</encoding> <source>${java.version}</source> <target>${java.version}</target> <compilerArgs> <arg>-parameters</arg> </compilerArgs> </configuration> </plugin> <!-- Source attach plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> 四.运行发布命令 mvn clean deploy
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。