maven packaging
Spring single structure project packaging
sring project packaging
//让src/main/java 和 src/resource/java 中的xml文件和properties文件都跟随打包
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
jsp packaging
<resources>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
Packaging of mapper mapping file directory when using mybatis
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
The ultimate approach to single-structure project packaging
**If none of the above methods work, use the following ultimate method: **Directly package all files under resources
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
Finally, click on the package in the life cycle to complete the packaging
Parent-child structure packaging
**Scenario:** After multi-module development of the previous project, the modules depend on each other, but a sub-module needs to be packaged and tested separately
When your project is upgraded and the component module is developed, the above packaging method can no longer be used. The packaged jar package is only a dozen or twenty k, and the following error will appear after running:
There must be something wrong with the way we pack it.
Solve the problem that subpackages cannot be packaged
Parent pom configuration: Can't add build! Can't add! Can't add!
Configure pom in the project that needs to be packaged
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--如果依赖有lombok后打包出错可以写上下面这段,无可以不写-->
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<mainClass>org.example.GatewayApplication</mainClass><!--项目启动类-->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include><!--打包resources下的所有文件-->
</includes>
</resource>
</resources>
</build>
Execute the packaging command under the path of the parent pom
mvn clean package -Dmaven.test.skip=true
After packaging, we can see that the jar package is not the previous project of less than 100k