maven命令行下载jar包 与 maven自动部署jar到私服

5 篇文章 0 订阅

命令行下载jar

mvn dependency:get -DremoteRepositories=http://192.129.123.233:8081/repository/public/ -DgroupId=jfqqq.test.com -DartifactId=data-test -Dversion=1.0.3-SNAPSHOT

基础知识

mirror中配置的库,默认只支持release库的拉取,snapshot是不支持的

所以如果想要拉取快照库,就需要给指定的库开启快照设置,如下:

           <repositories>
	            <repository>
	                <id>nexus</id>
	                <name>nexus</name>
	                <url>http://192.9.111.111:8081/repository/jfqqqq-public/</url>
	                <releases>
	                    <enabled>true</enabled>
	                </releases>
	                <snapshots>
	                    <enabled>true</enabled>
	                </snapshots>
	            </repository>
	        </repositories>

1.1 上面的这个配置可以写到项目的pom文件中,直接在<project>标签的根目录加上即可,如:

<?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 ">
    <modelVersion>1.1.1</modelVersion>
    <groupId>com.jfqqqq.test</groupId>
    <artifactId>jfqqqtest</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>

    <dependencies>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.7</version>
        </dependency>
          ...
    </dependencies>

    <properties>
        ...
    </properties>


    <repositories>
        <repository>
            <id>nexus</id>
            <name>nexus</name>
            <url>http://192.9.111.111:8081/repository/jfqqqq-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

1.2 或者配置到settings中,在settings中就需要在profiles里配:

	<profiles>
		<profile>
	        <id>myProfile</id>
	        <repositories>
	            <repository>
	                <id>nexus</id>
	                <name>nexus</name>
	                <url>http://192.9.111.111:8081/repository/jfqqqq-public/</url>
	                <releases>
	                    <enabled>true</enabled>
	                </releases>
	                <snapshots>
	                    <enabled>true</enabled>
	                </snapshots>
	            </repository>
	        </repositories>
		</profile>	
	</profiles>
     
	
    <activeProfiles> 
		<activeProfile>myProfile</activeProfile><!-- 注意值要与上面的<id>中的一致 -->
	</activeProfiles>

当然,这样配置后,mirror中就不需要再配了(一般需求下)

部署jar到私服

settings文件,基础知识见上面的即可。

然后是项目中的pom.xml,先上实例:

<?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">
    <parent>
        <artifactId>jfqqq.test</artifactId>
        <groupId>jfqqqq.test.com</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>jfqqq.test.one</artifactId>
    <version>0.0.2-SNAPSHOT</version>
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <dependencies>
        ...
    </dependencies>
    <distributionManagement>
        <snapshotRepository>
            <id>tdtNexus-snapshot</id>
            <name>Nexus Snapshot</name>
            <url>http://192.168.100.412:8080/repository/maven-snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>tdtNexus-releases</id>
            <name>Nexus Snapshot</name>
            <url>http://192.168.100.412:8080/repository/maven-releases/</url>
        </repository>
    </distributionManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

重点位置

1. <version/>标签中需要放置的内容中,如果是“-SHNAPSHAOT”结尾则会部署到snapshot库下,如果是“-RELEASE”则是放在release库下。

2. <distributionManagement />标签中配置SNAPSHOT和RELEASE库的地址,其中<repository />是release库,<snapshotRepository />是snapShot库。库的密码什么的见上面的基础知识即可。

3. <build/>标签中获用于配置将源代码打包,这时候就也会把源代码部署上去

补充:<distributionManagement/>标签中的两个maven地址,可以通过自己打开自己的maven私服,找到对应的服务(如下图),点击进去查看地址即可:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值