前言
本项目是多module的springcloud的项目,因为需要依赖第三方jar包,而客户的部署环境异常无法成功依赖导第三方jar包,所以需要自身项目带上jar包。本项目的hwyg-sms模块(为jar)依赖一些短信的jar,现将第三方的短信jar直接下载放到hwyg-sms模块中。
1、在模块中导入jar
2、配置pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>com.aliyuncs.dysmsapi</groupId>
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/aliyun-java-sdk-dysmsapi-1.1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.hfocean.common</groupId>
<artifactId>spring-boot-starter-aliyun-sms</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/spring-boot-starter-aliyun-sms-1.0.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>com.aliyuncs</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.20</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/aliyun-java-sdk-core-4.5.20.jar</systemPath>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
3、打包的时候一定要加入以下配置
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
将scope设置为system
表示被依赖项不会从maven仓库中寻找,而是从本地代码中寻找,而且打包的时候可以不用包进去,其他方式会提供次依赖。和compile一样,但是打包时候会exclude此jar。所以要加入此配置表示设置为system的依赖依然会被打包进来。
4、存在的小问题
但是打完war包之后解压包会发现依赖在lib-provided下面,而Tomcat是查询的lib下的依赖,所以还需要新增个配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${project.basedir}/lib</directory>
<targetPath>WEB-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>