背景:
公司前置的项目包对接客户公司的sdk包,由于此前置项目完全定制化,且改sdk包非通用包,不好上传至公司的maven私服使用,故引入本地jar包,此处总结改方案
1. 代码引入第三方jar包
在项目中新建成lib文件夹,结构与srv平级
2. pom文件修改
<dependency>
<groupId>cn.xxx</groupId>
<artifactId>xxx</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/lib/cn.xxx.xxx-1.0.0-SNAPSHOT.jar</systemPath>
</dependency>
打包插件配置
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<useUniqueVersions>false</useUniqueVersions>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>lib/cn.xxx.xxx-1.0.0-SNAPSHOT.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>target/lib</outputDirectory>
<excludeArtifactIds>
cn.xxx.xxx-1.0.0-SNAPSHOT.jar
</excludeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>copy-resources-ext</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/lib</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${basedir}/lib</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
该插件三个部分
- 将本地包打包至指定位置lib下
- 所有的jar包拷贝至target/lib下,出了改本地包
- 将所有的target/lib包拷贝至jar包外的lib包下(这样实现第三方jar包与业务包分离,而不是打包成一个整体,方便后续更新只更新指定的包)
至此,引入本地包可运行项目,打包也是正常
标签:1.0,cn,lib,xxx,jar,maven,本地 From: https://www.cnblogs.com/live2learn/p/18199915