I have to create test war and production war, which will have a different log4j.properties
file in the WEB-INF
directory. I have these files log4j.properties
(test war) and dev.log4j.properties
(for production enivorment).
How to copy the dev.log4j.properties
file into log4j.properties
file for production war?
Resource Filtering. You can use Maven to perform variable replacement on project resources. When resource filtering is activated, Maven will scan resources for property references surrounded by ${ and }.
Via the resources area in the pom you can filter files from their way src/main/resources to the target/classes folder. The lifecycle of Maven is not influenced by this. I have added resources successfully in . Jar file.
Create a "dev" and "prod" profile, selecting an alternate set of resources for each profile. Make Dev active by default.
<profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <resources> <resource> <directory>src/main/resources/dev</directory> </resource> </resources> </build> </profile> <profile> <id>prod</id> <build> <resources> <resource> <directory>src/main/resources/prod</directory> </resource> </resources> </build> </profile> </profiles>
Build using the desired profile via: mvn install -Pdev
or mvn install -Pprod
I solved this using the maven-resources plugin, where i created the prod directory which has the resources for production environment and copied them to WEB-INF/classes directory in process-resources phase.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>copy-prod-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>webapp/WEB-INF/classes</outputDirectory> <resources> <resource> <directory>src/main/resources/prod</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin>
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