Filtering Maven files into WEB-INF

后端 未结 4 1356
抹茶落季
抹茶落季 2021-01-31 02:18

I am trying to add some filtering to the application context file, which resides in the WEB-INF directory.

I have the file which is to be filtered (xmlgateway-context.

相关标签:
4条回答
  • 2021-01-31 02:45

    With filteringDeploymentDescriptors set to true

         <build>
            <finalName>web-project-name</finalName>
            <filters>
                <filter>src/main/resources/app.properties</filter>
            </filters>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <compilerArguments>
                            <endorseddirs>${endorsed.dir}</endorseddirs>
                        </compilerArguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                        <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
                    </configuration>
                </plugin>           
            </plugins>
        </build>
    
    0 讨论(0)
  • 2021-01-31 02:46

    you should configure filtering via the maven war plugin: checkout these examples.

    0 讨论(0)
  • 2021-01-31 03:08
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <webResources>
                    <resource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                        <includes>
                            <include>**/xmlgateway-context.xml</include>
                         </includes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
    

    Add the above to your pom.xml. EDIT: Just to explain what the above conf is doing. With this added, mvn is going to filter files under src/main/webapp/WEB-INF and in particular filter the included files xmlgateway-context.xml and after filtering it is going to push the files in WEB-INF folder (thats what the target tag is saying).

    Update if something is not clear.

    0 讨论(0)
  • 2021-01-31 03:11

    Put the file xmlgateway-context.xml in src/main/webapp/WEB-INF and configure like this:

    <build>
        <filters>
            <filter>src/main/filters/config-${targetenv}.properties</filter>
        </filters>
        <resources>
            <resource>
                    <filtering>true</filtering>
                    <directory>src/main/webapp/WEB-INF</directory>
            </resource>
        </resources>
    </build>
    
    0 讨论(0)
提交回复
热议问题