Java – pass custom environment variables to Maven

I'm looking for a way to pass environment variables to cargo containers Something like this:

<plugin>
  <groupId>org.codehaus.cargo>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
    <environmentVariables>
      <myCustomVariable>value</myCustomVariable>
      ...

Solution

AFAIK, the goods are only allowed to pass the system properties mentioned in passing system properties and Maven tips, as shown in the following example: –

<container>
  [...]
  <systemProperties>
    <myproperty>myvalue</myproperty>
  </systemProperties>
</container>

The solution may be to link system properties to environment variables, as shown in the following example: –

<container>
  [...]
  <systemProperties>
    <myproperty>${env.MY_ENV_VAR}</myproperty>
  </systemProperties>
</container>

Usually we can only use OS to set environment variables Anyway, there is another solution. Set it by using Java, such as how do I set environment variables from Java? Described

I always use this technique to set environment variables during unit testing by placing them in the JUnit test suite with @ beforeclass and setting them as empty strings with @ afterclass

Please note that the official java tutorial also mentions environment variables and passing environment variables to new processes

I hope this may help

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>