Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set java system property during maven 2 compile?

Tags:

maven-2

maven

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!

like image 970
Stuck Avatar asked Mar 14 '12 17:03

Stuck


People also ask

How do I set system properties in Maven?

To provide System Properties to the tests from command line, you just need to configure maven surefire plugin and use -D{systemproperty}={propertyvalue} parameter in commandline. Run Single Test with Maven : $ mvn test -Dtest=MessageUtilTest#msg_add_test -Dmy_message="Hello, Developer!"

What is systemPropertyVariables in POM XML?

systemPropertyVariables. Maven Surefire plugin provides the configuration parameter systemPropertyVariables to set system properties. The properties defined here will be available in the unit tests.

How do I set system properties in eclipse?

In your Eclipse environment, select the java project, right-click, and select Properties. Click Run/Debug Settings. Select New... > Java Application, and click the Environment tab.


1 Answers

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>
like image 76
yegor256 Avatar answered Sep 20 '22 20:09

yegor256