参考文献:
https://blog.csdn.net/xixingzhe2/article/details/124381885
http://t.zoukankan.com/hzm112567-p-6531654.html
1.背景
在对接第三方厂商时,会提供对应jar,maven公开仓库上没有发布,提供的处理方法。
1)上传的公司私服。
2)systemPath方式加载本地jar。
本文要讲的就是使用systemPath方式加载本地jar。
2.项目引用
<dependency>
<groupId>netty</groupId>
<artifactId>all</artifactId>
<version>4.0.23</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/netty-all-4.0.23.Final.jar</systemPath>
</dependency>
groupId:此名称可自定义netty 为自定义的名称
artifactId:此名称可自定义,all 为自定义的名称,不过这个最好与加载的jar名称保持一致。
version:此版本号可自定义,不过好与加载的jar保持一致。
scope:使用system。
systemPath:本地jar文件你放在系统文件的目录,${project.basedir}表示项目根目录。lib和src为同级目录。
3.springboot插件配置(jar 包部署)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!--jar 部署的时候使用这个插件,war包部署时需要注释掉-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.6.9</version>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
注意:<includeSystemScope>true</includeSystemScope>作用:代表maven打包时会将外部引入的jar包(比如在根目录下或resource文件下的外部jar包)打包到项目jar,在服务器上项目才能运行,不加此配置,本地可以运行,因为本地可以在lib下找到外部包,但是服务器上jar中是没有的。
4.springboot 插件配置(war 包部署)
<build>
<finalName>cfcc</finalName>
<!--war 部署的时候使用这个插件,jar包部署时需要注释掉-->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<!--将工程目录下的jar包拷贝到WEB-INF包下-->
<webResources>
<resource>
<directory>${project.basedir}/lib</directory>
<targetPath>WEB-INF/lib</targetPath>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
日志:
[INFO] Copying webapp webResources [D:\work\release\v1.0.0\release\business-webapp/lib/] to [D:\work\release\v1.0.0\release\business-webapp\target\basedp]
注意:
<!--war包时需要加载此依赖,jar包时需要去掉此依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>