Java maven在生成时传递命令参数以覆盖属性
在我们的应用程序中,我们有一个白标签系统 在Java maven在生成时传递命令参数以覆盖属性,java,maven,maven-3,Java,Maven,Maven 3,在我们的应用程序中,我们有一个白标签系统 在application.properties中有一个设置theme=default 该设置被注入到Spring管理的bean中,然后该bean通过框架对应用程序进行操作,如添加正确的css等 我希望能够做到的是,在构建时(war创建),指定主题,例如mvn clean install-theme:some theme。然后将更新application.properties,并修改theme 如果只运行mvn clean install,则theme=d
application.properties
中有一个设置theme=default
该设置被注入到Spring管理的bean中,然后该bean通过框架对应用程序进行操作,如添加正确的css等
我希望能够做到的是,在构建时(war创建),指定主题,例如mvn clean install-theme:some theme
。然后将更新application.properties
,并修改theme
如果只运行mvn clean install
,则theme=default
或未修改的
这可能吗?通过命令行设置属性的正确方法是使用-D
:
mvn -Dproperty=value clean package
它将覆盖以前在pom.xml
中定义的任何属性
因此,如果您的pom.xml中有:
<properties>
<theme>myDefaultTheme</theme>
</properties>
我猜你要找的是maven构建概要文件和。您可以为每个主题指定一个概要文件,并根据概要文件更改application.properties中参数的值
e、 g
这种方法提供了根据配置文件进行定制的灵活性,因此可以说是批量定制。这与资源筛选相结合正是我所寻找的汉克斯,这正是我所寻找的
<properties>
<theme>halloween</theme>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>white</id>
<properties>
<theme>white</theme>
<prop1>xyz</prop1>
<!--and some other properties-->
</properties>
</profile>
<profile>
<id>default</id>
<properties>
<theme>default</theme>
<prop1>abc</prop1>
<!--and some other properties-->
</properties>
</profile>
</profiles>
my.theme=${theme}
my.custom.property=${prop1}