I've got two configuration files (with usernames and passwords for the database for the testing phase) in src\main\resources\{config.properties,config.default.properties}
During the development and my own testing I would like use src\main\resources\config.properties
. On packaging the project, I'd like to include src\main\resources\config.default.properties
as config.properties
in the single jar with dependencies. How can I tell this directly in the single pom.xml
? I tried to exclude src\main\resources\config.properties
with this section, but even that didn't work:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.great.tech.Client</mainClass>
<packageName>com.great.tech.client</packageName>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Created-By>Great Technologies AG</Created-By>
<Version>${project.version}</Version>
<Title>Great Tech</Title>
</manifestEntries>
</archive>
<appendAssemblyId>false</appendAssemblyId>
<dependencySets>
<dependencySet>
<excludes>
<exclude>**/config.properties</exclude>
</excludes>
</dependencySet>
</dependencySets>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
You can define profile for environments
Then you can specify the property to be used in maven command like
mvn install -Pdev
this will refer dev properties file.Then add your properties files to
profiles/dev/config.properties
andprofiles/prod/config.properties
in the project so that-Pdev
can refer to the file. Finally add a plugin to copy the appropriate file to the resources: