需要在打包的那个项目模块下的pom文件中加入build属性
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.*</include>
</includes>
<!--是否替换资源中的属性-->
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.yml</include>
</includes>
<!--是否替换资源中的属性-->
<filtering>false</filtering>
</resource>
</resources>
<!-- 设置名称 -->
<finalName>smul-controller</finalName>
<plugins>
<!--设置应用 Main 参数启动依赖查找的地址指向外部 lib 文件夹-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- 项目所依赖的jar位于同一级的lib目录下-->
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 不指定单元测试 -->
<fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
<!-- 指定该Main Class为全局的唯一入口 -->
<mainClass>com.caeri.ict.smul.control.SmulControllerApplication</mainClass>
<layout>ZIP</layout>
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>repackage</goal><!–可以把依赖的包都打包到生成的Jar包中–>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
</plugin>
<!--设置将 lib 拷贝到应用 Jar 外面-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/smul-controller-lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</build>
这里有一个坑 目前还未解决,就是这样打包后可能影响k8s连接docker容器,启动job时报错
k8s启动job的坑解决了:主要是我的启动命令有问题 原来的启动命令没有添加 基础包和resouce和lib 修改后的命令:nohup java -Djava.ext.dirs=$JAVA_HOME/jre/lib/ext:自己分离后的依赖jar目录/, resource,lib -jar ***.jar