项目文件结构示意图:
maven中引用包
<dependency>
<groupId>ctec</groupId>
<artifactId>xxx-core</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/libs/ctec-xxx-core.jar</systemPath>
</dependency>
打包关键配置-方式一
war包和jar包略有不同,war包的lib要放入WEB-INF/lib/,jar包的lib要放入BOOT-INF/lib/,简单实用的pom打包代码。
<profiles>
<profile>
<id>war</id>
<!-- 默认激活本环境 -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<finalName>ygoclub</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>src/main/resources/lib</directory>
<targetPath>WEB-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<packaging>war</packaging>
</properties>
</profile>
<profile>
<id>jar</id>
<build>
<finalName>ygoclub</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 指定该Main Class为全局的唯一入口 -->
<mainClass>com.framework.RunApplication</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/resources/lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</resources>
</build>
<properties>
<packaging>jar</packaging>
</properties>
</profile>
</profiles>
打包关键配置-方式二
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
有朋自远方来,不亦乐乎?
为提供更好的知识分享,欢迎提出建议、指正问题,博客:风流三月1,微信号是 pgy1607974129 ,公众号是“ Ygo 工作室”。