使用maven 2.x设置环境变量

时间:2022-02-23 02:06:03

Is it possible to set environment variable with maven (OS: Linux)?

是否可以使用maven(OS:Linux)设置环境变量?

I already have user-defined properties (in the pom and in profiles.xml)....my problem is, how to execute following from Maven

我已经有了用户定义的属性(在pom和profiles.xml中)....我的问题是,如何从Maven执行以下操作

export GGA_FRE=/path

So will be possible, that every developer can set his own path for the GGA_FRE.

因此,每个开发人员都可以为GGA_FRE设置自己的路径。

2 个解决方案

#1


4  

This answer is not correct, at least not completely (see comments).
Unfortunately I can't delete it as it has been accepted. Your milage may vary.

这个答案是不正确的,至少不完全(见评论)。不幸的是我不能删除它,因为它已被接受。你的milage可能会有所不同。


Use the exec:exec mojo.

使用exec:exec mojo。

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
      <execution>
        <id>exportVar</id>
        <phase>initialize</phase>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <executable>export</executable>
      <arguments>
        <argument>GGA_FRE=${my.path}</argument>
      </arguments>
    </configuration>
  </plugin>

now call it like this mvn install -Dmy.path=/var/users/groucho

现在称之为mvn install -Dmy.path = / var / users / groucho

#2


0  

I don't think there is a Java way to set environment variable the way export command does (so that it is avaliable outside of Java). (see for example this question: How do I set environment variables from Java?)

我不认为有一种Java方法可以像导出命令那样设置环境变量(因此它可以在Java之外使用)。 (例如,请参阅此问题:如何从Java设置环境变量?)

However, you might hack you way around: for example use maven-exec plugin to run a shell script and then set the variable in the script. You might pass a parameter to your script to specify the variable value. (note that I have not tested this)

但是,您可能会遇到麻烦:例如,使用maven-exec插件运行shell脚本,然后在脚本中设置变量。您可以将参数传递给脚本以指定变量值。 (注意我还没有测试过这个)

#1


4  

This answer is not correct, at least not completely (see comments).
Unfortunately I can't delete it as it has been accepted. Your milage may vary.

这个答案是不正确的,至少不完全(见评论)。不幸的是我不能删除它,因为它已被接受。你的milage可能会有所不同。


Use the exec:exec mojo.

使用exec:exec mojo。

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
      <execution>
        <id>exportVar</id>
        <phase>initialize</phase>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <executable>export</executable>
      <arguments>
        <argument>GGA_FRE=${my.path}</argument>
      </arguments>
    </configuration>
  </plugin>

now call it like this mvn install -Dmy.path=/var/users/groucho

现在称之为mvn install -Dmy.path = / var / users / groucho

#2


0  

I don't think there is a Java way to set environment variable the way export command does (so that it is avaliable outside of Java). (see for example this question: How do I set environment variables from Java?)

我不认为有一种Java方法可以像导出命令那样设置环境变量(因此它可以在Java之外使用)。 (例如,请参阅此问题:如何从Java设置环境变量?)

However, you might hack you way around: for example use maven-exec plugin to run a shell script and then set the variable in the script. You might pass a parameter to your script to specify the variable value. (note that I have not tested this)

但是,您可能会遇到麻烦:例如,使用maven-exec插件运行shell脚本,然后在脚本中设置变量。您可以将参数传递给脚本以指定变量值。 (注意我还没有测试过这个)