[英]maven-assembly-plugin: use config.properties during development and but pack config.default.properties as config.properties on jar-with-dependencies
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
.我在
src\main\resources\{config.properties,config.default.properties}
中有两个配置文件(用于测试阶段的数据库的用户名和密码)在开发和我自己的测试期间我想使用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.在打包项目时,我想将
src\main\resources\config.default.properties
作为config.properties
包含在具有依赖关系的单个 jar 中。 How can I tell this directly in the single pom.xml
?如何在单个
pom.xml
中直接说明这一点? I tried to exclude src\main\resources\config.properties
with this section, but even that didn't work:我试图在本节中排除
src\main\resources\config.properties
,但即使这样也没有用:
<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您可以为环境定义配置文件
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
</properties>
</profile>
Then you can specify the property to be used in maven command like mvn install -Pdev
this will refer dev properties file.然后您可以指定要在 maven 命令中使用的属性,例如
mvn install -Pdev
这将引用 dev 属性文件。
Then add your properties files to profiles/dev/config.properties
and profiles/prod/config.properties
in the project so that -Pdev
can refer to the file.然后将您的属性文件添加到项目中的
profiles/dev/config.properties
和profiles/prod/config.properties
,以便-Pdev
可以引用该文件。 Finally add a plugin to copy the appropriate file to the resources:最后添加一个插件,将相应的文件复制到资源中:
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>copy-file</id>
<phase>generate-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>profiles/${build.profile.id}/config.properties</sourceFile>
<destinationFile>src/main/resources/config.properties</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.