1

I would like to specify some system properties in my applicatio (deterined at compile time).

I am using the spring boot maven plugin to compile

Currently, according to this questions: Specify system property to Maven project I tried the following setup (however this does not work as it is for a different plugin)

    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>application.boot.AppStarter</mainClass>
                <systemProperties>
                    <systemProperty>
                        <name>application.version</name>
                        <value>${application.version}</value>
                    </systemProperty>
                    <systemProperty>
                        <name>release.date</name>
                        <value>${timestamp}</value>
                    </systemProperty>
                </systemProperties> 
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

How can i specify the properties in this plugin?

Community
  • 1
  • 1
mangusbrother
  • 3,988
  • 11
  • 51
  • 103
  • the spring-boot-maven-plugin just creates an executable jar. What are you trying to do with the system properties?Do you mean to say you need some properties to be available in a property file when you execute the generated jar? repackage doesn't support any systemProperties parameter as seen in http://docs.spring.io/spring-boot/docs/1.2.0.BUILD-SNAPSHOT/maven-plugin/repackage-mojo.html – coderplus Oct 26 '14 at 15:09
  • I would like two things. 1) The Hermes.version maven pom.xml property and 2) The date at which the jar was built To be accessible from within my code. If they are as system properties I could access them using System.getProperty("") – mangusbrother Oct 26 '14 at 15:46

1 Answers1

1

Java system properties which you add are only accessible by the process they are added to.So even if you manage to add some system properties during the Maven build, it will no longer be there when the build is done.

What will happen if you distribute your jar to someone else. How do you expect these properties to be available?

Solution

Refer this post to see how to access the artifactId and version at runtime In a similar fashion you can add the timestamp entry as well to the src/main/resources/project.properties

buildTimestamp=${timestamp}

timestamp is not a pre-defined property like project.version or project.artifactId.So you will have to set extract the timestamp from the Maven property ${maven.build.timestamp} and set it as value to your timestamp property. This is already answered in this question.

Community
  • 1
  • 1
coderplus
  • 5,793
  • 5
  • 34
  • 54
  • While it is now trying to read the properties successfully, I am getting a : Could not resolve placeholder 'property.name' in string value '${property.name}' – mangusbrother Oct 26 '14 at 17:01
  • something similar to this? http://stackoverflow.com/questions/20244696/could-not-resolve-placeholder-in-string-value – coderplus Oct 26 '14 at 17:10
  • My properties are being read, as if i place them as normal values it is read successfuly. If i use ${} however it won't – mangusbrother Oct 26 '14 at 17:40
  • check if resource filtering is working correctly check target/classes/project.properties after a Maven build. – coderplus Oct 26 '14 at 18:56
  • the property file is being adapted successfulyl. I'm having some issues with the property reading. i'll look into it a bit more and come back at you – mangusbrother Oct 27 '14 at 09:56
  • ok this is working after a mvn install. The only issue remaining is that it will not work from an executino in eclipse since It tries to load maven.build.timestamp. Is there any way to set this appropriately? – mangusbrother Oct 27 '14 at 10:05
  • that property won't be set when you are building from eclipse(as you don't really have a build. In case, it's breaking something, you can provide a default value which eclipse can use : https://bugs.eclipse.org/bugs/show_bug.cgi?id=388874#c4 – coderplus Oct 27 '14 at 10:46