1

System.getProperty("hello.world.two") returns null. Tried compile/initialize/package phase.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
        <execution>
            <!-- any phase before your app deploys -->
            <phase>prepare-package</phase>
            <goals>
                <goal>set-system-properties</goal>
            </goals>
            <configuration>
                <properties>
                    <property>
                        <name>hello.world.two</name>
                        <value>Hello World!</value>
                    </property>
                </properties>
            </configuration>
        </execution>
    </executions>
</plugin>
spider
  • 29
  • 2
  • 6
  • When did you call `System.getProperty("hello.world.two")`? During the Maven build? In your application at run-time? – Tunaki Nov 05 '15 at 10:15
  • During application run-time – spider Nov 05 '15 at 10:17
  • Then this is expected: during the Maven build, the system property is set. But your application is ran in another VM. Instead, you can write this property to a text file and read this file in your app. – Tunaki Nov 05 '15 at 10:19
  • How to write this property to a text file. – spider Nov 05 '15 at 10:22
  • Refer to [this question](http://stackoverflow.com/q/3532135/1743880): this talks about the project version but it works for any property. – Tunaki Nov 05 '15 at 10:23
  • 1
    Thanks. Seems writing the property to a text file needs maven-resources-plugin – spider Nov 05 '15 at 10:33
  • Is there a way (maven plugin) to read the Maven build system property using System.getProperty() in application runtime directly without writing to a file. – spider Nov 05 '15 at 10:37
  • No: it is different VM executions so different system properties. – Tunaki Nov 05 '15 at 10:38
  • maven-surefire-plugin;s systemPropertyVariables supports this use case. But surefire-plugin used for unit testing, I need it for application. – spider Nov 05 '15 at 10:42
  • What is exactly the purpose you need the property for? Thought about `src/main/resources` folder? – khmarbaise Nov 05 '15 at 11:56
  • We have couple of properties file for each application. We need to read the property file name for every application. Application1 has user.properties1 and Application2 has user.properties2. Based on this name(property file name) we will load the property file for each application. – spider Nov 05 '15 at 14:53
  • All the properties files are in the src/main/resources folder – spider Nov 05 '15 at 14:54

0 Answers0