How can i set up an environment variable (in other words internally accessible by System.getenv("APP_HOME")
in a pom file?
如何在pom文件中设置环境变量(换句话说,System.getenv(“APP_HOME”)可以在内部访问?
APP_HOME=/path/home
I realize i can set it up in .profile
, but wonder if pom can do the same trick.
我意识到我可以在.profile中设置它,但是想知道pom是否可以做同样的技巧。
Per bmargulies's suggestion below, i tried the following, without luck
按照下面的bmargulies的建议,我尝试了以下,没有运气
<build>
<finalName>KvpStore</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<includes>
<include>**/*Test*.java</include>
</includes>
<environmentVariables>
<APP_NAME>blah_blah</APP_NAME> <------------------------
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
2 个解决方案
#1
-1
The documentation of the maven-surefire-plugin show examples and describes how to do such things of setting up system properties.
maven-surefire-plugin的文档显示了示例,并描述了如何设置系统属性。
<configuration>
<systemPropertyVariables>
<propertyName>propertyValue</propertyName>
<buildDirectory>${project.build.directory}</buildDirectory>
[...]
</systemPropertyVariables>
</configuration>
It might be better to use them instead of environment variable, cause it's simpler to use them, cause env variable needed to setup correctly and the cmd.exe and the jvm must be restarted to get them working.
使用它们而不是环境变量可能更好,因为使用它们更简单,导致需要正确设置的env变量,必须重新启动cmd.exe和jvm才能使它们正常工作。
It is not necessary to configure the includes for the tests, cause maven-surefire-plugin has already the following defaults:
没有必要为测试配置包含,因为maven-surefire-plugin已经具有以下默认值:
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
#2
28
Some plugins, like surefire, let you set them. There's no way, in general, in the pom.
有些插件,比如surefire,可以让你设置它们。一般来说,在pom中没有办法。
The doc for surefire is is here. Surefire will set environment variables for the duration of the run of the tests, not for anything else. And you have to make surefire fork.
肯定的文件就在这里。 Surefire将在测试运行期间设置环境变量,而不是其他任何东西。你必须确保火力叉。
In the configuration ...
在配置中......
<configuration>
<forkMode>always</forkMode>
<environmentVariables>
<var1>val1</var1>
</environmentVariables>
</configuration>
#1
-1
The documentation of the maven-surefire-plugin show examples and describes how to do such things of setting up system properties.
maven-surefire-plugin的文档显示了示例,并描述了如何设置系统属性。
<configuration>
<systemPropertyVariables>
<propertyName>propertyValue</propertyName>
<buildDirectory>${project.build.directory}</buildDirectory>
[...]
</systemPropertyVariables>
</configuration>
It might be better to use them instead of environment variable, cause it's simpler to use them, cause env variable needed to setup correctly and the cmd.exe and the jvm must be restarted to get them working.
使用它们而不是环境变量可能更好,因为使用它们更简单,导致需要正确设置的env变量,必须重新启动cmd.exe和jvm才能使它们正常工作。
It is not necessary to configure the includes for the tests, cause maven-surefire-plugin has already the following defaults:
没有必要为测试配置包含,因为maven-surefire-plugin已经具有以下默认值:
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
#2
28
Some plugins, like surefire, let you set them. There's no way, in general, in the pom.
有些插件,比如surefire,可以让你设置它们。一般来说,在pom中没有办法。
The doc for surefire is is here. Surefire will set environment variables for the duration of the run of the tests, not for anything else. And you have to make surefire fork.
肯定的文件就在这里。 Surefire将在测试运行期间设置环境变量,而不是其他任何东西。你必须确保火力叉。
In the configuration ...
在配置中......
<configuration>
<forkMode>always</forkMode>
<environmentVariables>
<var1>val1</var1>
</environmentVariables>
</configuration>