Java:Maven在编译的jar中的pom.xml中存储系统属性的位置在哪里?

时间:2012-02-02 11:13:24

标签: plugins maven compiler-construction pom.xml system-properties

我们在pom.xml中的maven编译器插件定义中指定了一堆系统属性:

<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.... -->

执行jar时会自动加载

Maven如何为系统属性创建此自动加载行为?我想了解这种行为的实际实现。

1 个答案:

答案 0 :(得分:0)

这不是我期望的行为(除非我误解你)。编译时系统属性不应在运行时保留。

我创建了一个基本的maven项目,它只打印出系统属性,但它不包含插件配置中指定的系统属性。

System.getProperties().getProperty("aKey")在运行时返回null,即使编译器插件配置与您的相同。

运行的任何其他插件可能有效吗?你是如何访问系统属性的?