How to set env variables for maven to run test cor

2019-04-28 02:38发布

问题:

Is it possible to set env vars in pom.xml that junit tests uses? Netbeans can get env vars and builds project correnctly. But when i use command line (mvn clean -> mvn install), build fails due to test errors.

Thanks.

回答1:

There are two approaches I know.

Commandline:

You can pass it in command line like

mvn -DAM_HOME=conf install

Using pom :

If AM_HOM is the variable and the value is conf ,make entry like below.

<plugins>
    ...


 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        ...
        <configuration>
            ...
            <environmentVariables>
                <AM_HOME>conf</AM_HOME>
            </environmentVariables>
        </configuration>
    </plugin>

...
<plugins>