Set java system property during maven 2 compilation?

I have a maven profile and you want to set a property that is later available for System.getProperty (..) in java:

<profile>
  <id>local-dev</id>
  <properties>
    <my.comp.my.prop>myValue</my.comp.my.prop>
  </properties>
</profile>

I want it to System.getProperty("my.comp.my.prop")be "myValue", but it null.. How to install it correctly? :)

Thansk!

+5
source share
2 answers

maven cannot set a property available to your application from the runtime.

Instead, you can use maven to update the properties file in your codebase at build time, which can then be read by your application at run time. Different property values ​​can be set based on the profile, which allows your application to have different values ​​as desired.

, ( maven).

+1

properties-maven-plugin , :

<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>
+10

All Articles