使用 Maven AntRun 插件检查环境变量 [英] Checking an environment variable using the Maven AntRun plugin
问题描述
我正在尝试检查是否在 maven-antrun-plugin 中设置了 MULE_HOME 环境变量,但没有成功.这是我到目前为止所拥有的:
I'm trying to check and see if the MULE_HOME environment variable is set within the maven-antrun-plugin without success. Here's what I have so far:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>mule-deploy</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"
classpath="${settings.localRepository}/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"/>
<echo message="MULE_HOME is ${env.MULE_HOME}"/>
<if>
<isset property="env.MULE_HOME"/>
<then>
<echo message="MULE_HOME is set"/>
</then>
<else>
<echo message="MULE_HOME is not set"/>
</else>
</if>
</target>
</configuration>
</execution>
</executions>
</plugin>
输出为:
[echo] MULE_HOME is /<my development path>/mule
[echo] MULE_HOME is not set
检查环境变量时我缺少什么?
What am I missing to check an environment variable?
推荐答案
Java 以不同于系统属性的方式存储环境变量;System.getenv() 与 System.getProperties().我的猜测是 maven 没有将环境变量映射到系统属性中,而这正是 Ant 对 isset 的期望.尝试在您的 POM 中创建一个属性:
Java stores environment variables differently from system properties; System.getenv() vs. System.getProperties(). My guess is that maven isn't mapping environment variables into system properties which is what Ant is expecting with isset. Try creating a property in your POM:
<properties>
<mulehome>${env.MULE_HOME}</mulehome>
<properties>
然后使用
<isset property="mulehome"/>
这篇关于使用 Maven AntRun 插件检查环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!