Java: Where does Maven store system properties set in the pom.xml within a compiled jar?

1.4k Views Asked by At

We've specified a bunch of system properties in our maven compiler plugin definition within pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>${project.build.sourceEncoding}</encoding>

                <systemProperties>
                    <systemProperty>
                        <key>aKey</key>
                        <value>aValue</value>
                    </systemProperty>
                </systemProperties>
             <!-- ....etcetera.... -->

These are automatically loaded when the jar is executed

How does Maven create this auto-load behaviour for system properties? I'd like to understand the practical implementation of this behaviour.

1

There are 1 best solutions below

1
On

This is not behaviour I would expect (unless I am misunderstanding you). Compile-time system properties should not be persisted at runtime.

I created a basic maven project that just prints out the system properties and it did not contain the system property specified in plugin configuration.

System.getProperties().getProperty("aKey") returned null at runtime even with compiler plugin configured the same as yours.

Any other plugins running that might have an effect? How are you accessing the system properties?