As you can see, I have config folder where I have two more folders dev and prod. Each one has two file with the same name but different values.
/config/dev/mail.properties
mail.server=smtp.gmail.com
mail.port=25
mail.from=abc@gmail.com
mail.to=xyz@gmail.com
/config/prod/mail.properties
mail.server=smtp.mycompany.com
mail.port=25
mail.from=emelendez@mycompany.com
mail.to=emelendez@mycompany.com
Why do we do that?
We have different environments and each one has his own configuration. Instead of re-write the file properties we can use profiles using maven. Configuration is attached bellow:
In your pom.xml file you need that:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<profiles> | |
<profile> | |
<id>prod</id> | |
<build> | |
<plugins> | |
<plugin> | |
<artifactId>maven-antrun-plugin</artifactId> | |
<executions> | |
<execution> | |
<phase>prepare-package</phase> | |
<goals> | |
<goal>run</goal> | |
</goals> | |
<configuration> | |
<tasks> | |
<copy file="config/prod/quartz.properties" | |
tofile="${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/quartz.properties" /> | |
<copy file="config/prod/mail.properties" | |
tofile="${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/mail.properties" /> | |
</tasks> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
</profile> | |
<profile> | |
<id>dev</id> | |
<build> | |
<plugins> | |
<plugin> | |
<artifactId>maven-antrun-plugin</artifactId> | |
<executions> | |
<execution> | |
<phase>prepare-package</phase> | |
<goals> | |
<goal>run</goal> | |
</goals> | |
<configuration> | |
<tasks> | |
<copy file="config/dev/quartz.properties" | |
tofile="${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/quartz.properties" /> | |
<copy file="config/dev/mail.properties" | |
tofile="${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/mail.properties" /> | |
</tasks> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
</profile> | |
</profiles> | |
</project> |
mvn -Pdev clean package -Dmaven.test.skip