如何用 Maven 属性替换 web.xml 中的值? [英] How to replace a value in web.xml with a Maven property?
本文介绍了如何用 Maven 属性替换 web.xml 中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 Maven 项目,它将一些测试文件下载到它的构建目录 ./target/files
.然后这些文件应该可供 servlet 使用,我可以通过将完整路径硬编码为 servlet 的 <init-param>
来轻松实现:
I have a Maven project that downloads some test files into its build directory ./target/files
. These files should then be available to a servlet, which I can easily achieve by hardcoding the full path as an <init-param>
of the servlet:
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>my.package.TestServlet</servlet-class>
<init-param>
<param-name>filepath</param-name>
<param-value>/home/user/testproject/target/files</param-value>
</init-param>
</servlet>
如何避免对完整路径进行硬编码并改用动态参数替换?我尝试了以下方法,但没有奏效:
How can I avoid hardcoding the full path and use a dynamic parameter replacement instead? I tried the following, but it did not work:
<param-value>${project.build.directory}/files</param-value>
推荐答案
添加到您的 pom 部分:
Add to your pom section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
<includes>
<include>**/web.xml</include>
</includes>
</resource>
</webResources>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
有关详细信息,请参阅Maven:自定义 Web 应用项目的 web.xml
这篇关于如何用 Maven 属性替换 web.xml 中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文