注:此方式只适用于springmvc项目,springboot项目不可用!
若是springboot项目可参考:https://www.cnblogs.com/007sx/p/12442386.html
完整的引入三方jar包含2部分,缺一不可,
第一部分为编写代码阶段,编译时引用!
第二部分为打包成war阶段,运行时引用!
示例(多模块项目,单模块同理,以下也有说明!):
第一部分(编译调试时使用):
目录结构以及jar所在目录如下:
pom.xml中:
<dependency> <groupId>com.testgroupId> <artifactId>testjarartifactId> <version>0.0.1version> <scope>systemscope> <systemPath>${basedir}/src/main/resources/lib/test.jarsystemPath> dependency>
第二部分(打包时使用):
pom.xml(其它模块)中:
<build> <finalName>${project.artifactId}finalName> <plugins> <plugin> <artifactId>maven-war-pluginartifactId> <version>3.2.0version> <configuration> <webResources> <resource> <directory>../cashloan-component/src/main/resources/libdirectory> <targetPath>WEB-INF/libtargetPath> <includes> <include>**/*.jarinclude> includes> resource> webResources> configuration> plugin> plugins> build>
说明:由于此pom.xml是子模块的,所以引入其它模块下的jar需要../xxx形式,如果是单模块项目,直接${basedir}/xxx即可!
最后打包的效果:
target/xxx/WEB-INF/lib/test.jar 存在即可!
完成这步骤代码即可正常构建运行和打包部署!
注:目前存在的问题,打包之后会在classes目录下target/xxx/WEB-INF/classes或者target/classes目录下多出来一个lib(示例中resources下目录命名为lib)目录里面存放的是三方jar,这个jar在项目运行中是用不到的,所以浪费了传输war包的时间!还没找到很好的解决方案,希望多多评论交流!
(已解决!)
方案分为单模块和多模块。
- 单模块pom.xml:只需在war打包插件中排除即可,如:
<packagingExcludes>WEB-INF/classes/lib/*.jarpackagingExcludes>
- 多模块的被依赖模块pom.xml中(即最终打成jar的模块):
<build> <resources> <resource> <directory>src/main/resourcesdirectory> <filtering>falsefiltering> <excludes> <exclude>lib/*.jarexclude> excludes> resource> resources> build>
当然,多模块时,2种方式都加上也可以,一劳永逸!
Original: https://www.cnblogs.com/007sx/p/12439620.html
Author: 007少侠
Title: spring项目(springmvc)(多模块/单模块)maven打包引入第三方jar方式,使用scope:system配置systemPath编译,不用添加到本地仓库!
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/541576/
转载文章受原作者版权保护。转载请注明原作者出处!