活用maven使web.xml可以用maven变量
废话不多说,直接上代码
<build>
<finalName>${finalWarName}</finalName>
<defaultGoal>compile</defaultGoal>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>WEB-INF/web.xml</include>
</includes>
<targetPath>${project.build.directory}/${project.build.finalName}</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<!-- http://maven.apache.org/plugins/maven-war-plugin/ -->
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
<outputDirectory>${war.outpath}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
重点是在resource中包含了web.xml并将其输出至默认目录,并在war插件中指明webXml属性,此二者缺一不可
效果:
打包前:
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>${datasource.type}</param-value>
</context-param>
打包后:
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>JDBC</param-value>
</context-param>