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.xml) in the folder /src/main/resources.
I have the properties files (config-e05.properties) in the folder src/main/filters
And I have the POM set up as follows:
<!-- environment profiles --> <profiles> <profile> <id>e04</id> <properties> <targetenv>e04</targetenv> </properties> </profile> <profile> <id>e05</id> <properties> <targetenv>e05</targetenv> </properties> </profile> </profiles> <!-- build settings (filtering) --> <build> <filters> <filter>src/main/filters/config-${targetenv}.properties</filter> </filters> <resources> <resource> <targetPath>WEB-INF</targetPath> <filtering>true</filtering> <directory>src/main/resources</directory> </resource> </resources> </build>
This will mvn install correctly, but when I open the output war file, I was expecting the file xmlgateway-context.xml to be in the /WEB-INF directory, but it ends up in the folder /WEB-INF/classes/WEB-INF.
How can I get this file into the right place.
Alternatively, can I put the application context into a different location and have it referenced there.
This component has been built from the filtering process/code in Maven Resources Plugin. The goal is to provide a shared component for all plugins that needs to filter resources.
I know this question is three years now, but just in case anybody is still wondering how to do it : In eclipse , right click on your project's name then select Java EE Tools-> Generate Deployment Descriptor Stub. And voila, the web. xml file is automatically created.
xml file in the current Maven project, relative to the location of pom. xml . The default is src/main/webapp/WEB-INF/web.
<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.
you should configure filtering via the maven war plugin: checkout these examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With