How to set up an environment variable in mvn pom?

后端 未结 2 1242
孤城傲影
孤城傲影 2021-01-03 21:11

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         


        
相关标签:
2条回答
  • 2021-01-03 21:29

    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>
    

    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>
    
    0 讨论(0)
  • 2021-01-03 21:29

    Some plugins, like surefire, let you set them. There's no way, in general, in the 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.

    In the configuration ...

    <configuration>
      <forkMode>always</forkMode>
      <environmentVariables>
         <var1>val1</var1>
      </environmentVariables>
    </configuration>
    
    0 讨论(0)
提交回复
热议问题