Maven使用本地dev jar

背景

一个本地开发的jar需要在一个maven工程中引用,引用过程中发生的一些问题。

过程

上传到私服

因为maven是下载使用,所以直接上传到私服。

  • M2_HOME/setting.xml
<server>

<id>deployment</id>

<username>deployment</username>

<password>deployment账号的密码</password>

</server>
  • pom.xml
<distributionManagement>
<repository>
<id>nexus-snapshots</id>
<url>http://maven.dev.sh.马赛克.com:8081/nexus/content/repositories/snapshots/</url>
</repository>
</distributionManagement>
  • mvn clean package deploy

果不其然的报错了,账号权限不够,限于高权限账号的申请,此路暂时不通。

引用本地路径

由于我是先获得jar包的,所以上传到私服不行直接给路径引用jar,而不是后文的发布到本地仓库。
引用本地jar大致分为两种:

  • 不推荐的暴力指定
    直接暴力指定,这样会破坏maven苦心构建的依赖管理架构。
<dependency>
    <groupId>sample</groupId>
    <artifactId>com.sample</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>

暴力就暴力吧,反正这个jar的更新能掌握。警告!还好不是错误,但是警告总是不好的嘛。

[WARNING] 'dependencies.dependency.systemPath' for balabala... should not point at files within the project directory, ${project.basedir}/src/lib/bigdataqueryapi-client.jar will be unresolvable by dependent projects 

G之,发现正是maven推荐这样指定,maven更希望是用户从公(私)服或者本地仓库上引用一个jar包。

打包到本地仓库后引用

插件引用

暴力到底!

  • pom.xml
...
<dependency>
    <groupId>com.mylib</groupId>
    <artifactId>mylib-core</artifactId>
    <version>0.0.1</version>
</dependency>
...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.5.2</version>
        <executions>
            <execution>
                <id>install-external</id>
                <phase>clean</phase>
                <configuration>
                    <file>${basedir}/lib/mylib-core-0.0.1.jar</file>
                    <repositoryLayout>default</repositoryLayout>
                    <groupId>com.mylib</groupId>
                    <artifactId>mylib-core</artifactId>
                    <version>0.0.1</version>
                    <packaging>jar</packaging>
                    <generatePom>true</generatePom>
                </configuration>
                <goals>
                    <goal>install-file</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

有引用jar包的maven工程

  • 优雅的install
    直接mvn clean package install,然后在pom中引用。果不其然的错误!
[ERROR] ...was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

上述问题待解决

装逼的cmd

这么装逼的方法必须要试一试啊

mvn install:install-file -DgroupId=<com.yours> -DartifactId=<whosclient> -Dversion=<1.0> -Dpackaging=jar -Dfile=<file://D://lib//> -DgeneratePom=true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值