如何在mvn pom中设置环境变量? [英] How to set up an environment variable in mvn pom?

查看:158
本文介绍了如何在mvn pom中设置环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置环境变量(换句话说,System.getenv("APP_HOME")在内部可在pom文件中访问?)

How can i set up an environment variable (in other words internally accessible by System.getenv("APP_HOME") in a pom file?

APP_HOME=/path/home

我意识到我可以在.profile中进行设置,但是想知道pom是否可以起到相同的作用.

I realize i can set it up in .profile, but wonder if pom can do the same trick.

根据以下bmargulies的建议,我尝试了以下操作,但是没有运气

Per bmargulies's suggestion below, i tried the following, without luck

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

推荐答案

maven-surefire-plugin的文档显示了示例,并描述了如何进行设置系统属性的操作.

The documentation of the maven-surefire-plugin show examples and describes how to do such things of setting up system properties.

<configuration>
  <systemPropertyVariables>
    <propertyName>propertyValue</propertyName>
    <buildDirectory>${project.build.directory}</buildDirectory>
    [...]
  </systemPropertyVariables>
</configuration>

使用它们而不是环境变量可能会更好,因为使用起来更简单,导致需要正确设置env变量,并且必须重新启动cmd.exe和jvm才能使它们工作.

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.

由于

It is not necessary to configure the includes for the tests, cause maven-surefire-plugin has already the following defaults:

<includes>
 <include>**/Test*.java</include>
 <include>**/*Test.java</include>
 <include>**/*TestCase.java</include>
</includes>

这篇关于如何在mvn pom中设置环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆