是否可以在构建配置文件中设置环境变量,而不是在命令行中设置它们?
例如,当我使用测试环境(-Denv=test)时,我想启用调试器。
我想让maven这样做:
export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n"这样,我就可以快速地附加一个调试器,而不必一遍又一遍地重复键入相同的行。
我不相信在这种情况下对我有帮助:
<plugin>
...
<!-- Automatically enable the debugger when running Jetty -->
<argLine>-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n</argLine>
</configuration>
...
</plugin>沃尔特
发布于 2009-08-14 05:54:24
在最近的Maven版本中,您可以通过运行 mvnDebug 而不是mvn来激活调试器,mvnDebug bat/sh文件设置MVN__DEBUG_OPTS并将它们传递给java.exe。传入的值为:
set MAVEN_DEBUG_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000如果这还不够,这可能会起作用(请注意,我还没有测试过这一点,我会在完成测试后更新)。Maven读取以“env”为前缀的属性。在环境中,您可以通过添加前缀来设置环境变量。即:
<profile>
<id>dev</id>
<properties>
<env.MAVEN_OPTS>-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000<env.MAVEN_OPTS>
</properties>
</profile>更新: surefire插件允许您在测试执行期间使用specify system properties。配置如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<systemProperties>
<property>
<name>propertyName</name>
<value>propertyValue</value>
</property>
</systemProperties>
</configuration>
</plugin>如果这些都不适用于您,那么可以编写一个在您的概要文件中配置的小插件,该插件绑定到初始化阶段并设置您的变量。该插件的配置如下所示:
<plugin>
<groupId>name.seller.rich</groupId>
<artifactId>maven-environment-plugin</artifactId>
<version>0.0.1</version>
<executions>
<execution>
<id>set-properties</id>
<phase>initialize</phase>
<goals>
<goal>set-properties</goal>
</goals>
</execution>
</executions>
<configuration>
<properties>
<env.MAVEN_OPTS>-Xdebug -Xnoagent -Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000<env.MAVEN_OPTS>
</properties>
</configuration>
</plugin>在执行期间,插件将使用System.setProperty()设置每个传递的属性。如果前两种方法不合适或不起作用,这应该可以解决您的问题。
https://stackoverflow.com/questions/1275624
复制相似问题