2011-12-22 44 views
3

我試圖檢查MULE_HOME環境變量是否在maven-antrun-plugin中設置沒有成功。這是我到目前爲止有:使用Maven AntRun插件檢查環境變量

<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 

我錯過檢查的環境變量?

回答

3

Java存儲與系統屬性不同的環境變量; System.getenv()與System.getProperties()。我的猜測是,maven沒有將環境變量映射到系統屬性,這是Ant期望的isset。試着在你的POM創建一個屬性:

<properties> 
    <mulehome>${env.MULE_HOME}</mulehome> 
<properties> 

然後用

<isset property="mulehome"/> 
+0

一個說明:我的示例將在項目中創建一個maven屬性,而不是系統屬性,但antrun插件在運行之前將所有maven屬性複製到Ant項目中,所以它應該可以工作。 – tdrury 2011-12-23 02:52:54

0

中的taskdef線後,定義​​:

<property environment="env"/> 

我的Ant的記憶是一個有點生疏,但據我記得,你需要先定義它,然後才能使用$ {env.FOO_BAR}變量。我希望這有幫助。 :)