Java maven程序集插件:在开发过程中使用config.properties,但将config.default.properties打包为jar上的config.properties,并附带依赖项
在开发和我自己的测试期间,我在Java maven程序集插件:在开发过程中使用config.properties,但将config.default.properties打包为jar上的config.properties,并附带依赖项,java,maven,pom.xml,maven-assembly-plugin,exclude-constraint,Java,Maven,Pom.xml,Maven Assembly Plugin,Exclude Constraint,在开发和我自己的测试期间,我在src\main\resources\{config.properties,config.default.properties}中有两个配置文件(带有测试阶段数据库的用户名和密码),我想使用src\main\resources\config.properties。在打包项目时,我希望将src\main\resources\config.default.properties作为config.properties包含在带有依赖项的单个jar中。如何在单个pom.xml中
src\main\resources\{config.properties,config.default.properties}
中有两个配置文件(带有测试阶段数据库的用户名和密码),我想使用src\main\resources\config.properties
。在打包项目时,我希望将src\main\resources\config.default.properties
作为config.properties
包含在带有依赖项的单个jar中。如何在单个pom.xml
中直接说明这一点?我试图在本节中排除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>
maven汇编插件
3.3.0
带有依赖项的jar
com.great.tech.Client
com.great.tech.client
真的
大科技股份有限公司
${project.version}
高科技
假的
**/config.properties
组装
包裹
单一的
您可以为环境定义配置文件
<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>
<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>