- 修改步骤
- 指定新目录位置
app.dir
- 添加编译插件,指定编译字节码版本
- 添加clean插件,指定clean路径为
${app.dir}
位置 - 添加resources插件
- 先拷贝webapp目录/静态资源和动态页面 到
${app.dir}
位置 - 拷贝resources下的配置文件到
target/classes
目录 - 拷贝
target/classes
下的class和配置文件到${app.dir}/WEB-INF/classes
目录
- 添加dependency插件,将jar包拷贝到
${app.dir}/WEB-INF/lib
目录
- 修改build节点
<properties>
<!-- 新目录位置 -->
<app.dir>./target/web</app.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<build>
<finalName>emptyspring</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<!--编译插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!--clean 插件-->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>${app.dir}</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<!--先拷贝webapp目录/静态资源和动态页面-->
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!--目标位置-->
<outputDirectory>${app.dir}/</outputDirectory>
<resources>
<resource>
<!--源位置-->
<directory>./src/main/webapp/</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
<!-- 拷贝resources下的配置文件到target/class-->
<execution>
<id>copy-conf</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!--目标位置-->
<outputDirectory>./target/classes</outputDirectory>
<resources>
<resource>
<!--源位置-->
<directory>./src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
<!--拷贝target/class到WEB-INF/classes下-->
<execution>
<id>copy-classes</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!--目标位置-->
<outputDirectory>${app.dir}/WEB-INF/classes</outputDirectory>
<resources>
<resource>
<!--源位置-->
<directory>./target/classes</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!--拷贝maven的依赖jar包到/WEB-INF/lib/目录下-->
<outputDirectory>${app.dir}/WEB-INF/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>