Reputation: 12292
I have a maven profile and want to set a property which is later on available per System.getProperty(..) in java:
<profile>
<id>local-dev</id>
<properties>
<my.comp.my.prop>myValue</my.comp.my.prop>
</properties>
</profile>
I want System.getProperty("my.comp.my.prop")
to be "myValue"
but it's null
..
How do I set it correctly? :)
Thansk!
Upvotes: 6
Views: 8847
Reputation: 105053
properties-maven-plugin plugin will help you to do exactly what you're looking for:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<goals>
<goal>set-system-properties</goal>
</goals>
<configuration>
<properties>
<property>
<name>my.property.name</name>
<value>my.property.value</value>
</property>
</properties>
</configuration>
</execution>
</executions>
</plugin>
Upvotes: 9
Reputation: 52635
maven cannot set a property which can be accessed by your application from the environment at runtime.
Instead, you can use maven to update a property file in your codebase during build time, which can then be read by your application at runtime. Different values of the property can be set based on the profile, thereby allowing your application to have different values as desired.
Alternately, you can invoke the application setting the desired property in the environment manually (outside maven).
Upvotes: 1