Jar包
maven项目在ide中编译打包出jar包,要注意别把配置文件.properties
打包进去。
<build>
<plugins>
<!-- 打包插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-maven-plugin.version}</version>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<excludes>
<exclude>**/apollo-env.properties</exclude>
<!-- exclude>**/application.properties</exclude -->
<exclude>**/log4j2.xml</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
war包
maven项目在ide中编译出war包,注意要把资源文件
打包进去。
但是经过集成环境打war包会出现war包中打不进xml、properties等文件。这样打war包不会报错,但是war包放进tomcat中部署就报错了。
解决方法:
在pom.xml的build节点配置src/main/java和src/main/resources
<build>
<resources>
<!-- 编译之后包含xml -->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<!-- 编译之后包含xml和properties -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
参考:
https://blog.csdn.net/qq1940879801/article/details/77716124