Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
445 views
in Technique[技术] by (71.8m points)

servlets - How to replace a value in web.xml with a Maven property?

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

See Maven: Customize web.xml of web-app project for more details


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...