1、如果是springboot或者springcloud项目,就是比较简单的常规配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
有本地依赖的时候,就需要加上
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
2.配置文件和依赖的jar包单独分离:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<!--<includeScope>system</includeScope>-->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- 资源文件输出目录 -->
<outputDirectory>${project.build.directory}/config</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<!-- 不需要分离出来的文件,过滤掉,就不拷贝出来了 -->
<exclude>mapper/**/*.xml</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<!-- 配置文件分离,这里过滤配置文件,不要打包到jar里面 -->
<exclude>*.properties</exclude>
<exclude>*.xml</exclude>
<exclude>*.yml</exclude>
</excludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.xxx.MainClass</mainClass>
</manifest>
<manifestEntries>
<!--<Class-Path>config/ lib/本地依赖的包在这里手动加入maniest.jar</Class-Path>-->
<Class-Path>config/ </Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>