Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing custom environment variables to maven cargo

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

<plugin>
  <groupId>org.codehaus.cargo>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
    <environmentVariables>
      <myCustomVariable>value</myCustomVariable>
      ...
like image 406
hertzsprung Avatar asked Jun 17 '11 10:06

hertzsprung


People also ask

How do I pass an environment variable in Maven?

Add M2_HOME, M2, MAVEN_OPTS to environment variables. Set the environment variables using system properties. Open command terminal and set environment variables. Open command terminal and set environment variables.

What is cargo maven2 plugin?

The Maven Cargo plugin comes with support for containers, where a container represents a Java EE server. As Payara Server Community is derived from GlassFish, Payara Server is able to use the GlassFish container with the Maven Cargo Plugin.

How do I set environment variables in rust?

Set an environment variable in Rust You can set an environment variable (for the scope of the currently running process) using the standard library too. To do so, we use env::set_var(key, value) .

How do I set my M2 at home?

Set M2_HOME & PATHCreate an environment variable named M2_HOME which refers to directory where maven was untarred/ unzipped. and then add this variable to PATH environment variable. $>export PATH=$M2_HOME/bin:$PATH. Click OK, then Edit the 'Path' user variable to add M2_HOME\bin folder in it.


1 Answers

AFAIK, The cargo only allow to pass the system properties as mentioning at Passing system properties and Maven Tips as the following example: -

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

The workaround may be link that system properties to the environment variable as the following example:-

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

Normally we are only able to set the environment variable by using the OS way. Anyhow there also is a workaround for setting it by using Java as mentioning at How do I set environment variables from Java?.

I always use this tip for setting up the environment variables during unit testing by putting them to the JUnit test suit with @BeforeClass and set them to be empty String with @AfterClass.

Please note that the formal Java Tutorial also mentions about Environment Variables and Passing Environment Variables to New Processes.

I hope this may help.

like image 87
Charlee Chitsuk Avatar answered Oct 05 '22 00:10

Charlee Chitsuk