[英]Ant - build script does not find pathelement defined in a properties file
我有一個具有以下目標的螞蟻構建腳本:
<target name="_initLiveProps">
<property file="buildscripts/live.properties"/>
</target>
<target name="buildLive" depends="_initLiveProps">
<property file="buildscripts/live.properties"/>
</target>
在構建腳本中,我聲明了幾個pathelements,如下所示:
<path id="project.class.path">
<pathelement location="./../lib/log4j-1.2.16.jar" />
<pathelement location="${product-def.jar}"/>
</path>
product-def.jar定義在buildscripts / live.properties文件中定義為
product-def.jar=./../lib/product-def/live/product-def.jar
當我構建項目(使用ant buildLive)時,出現編譯錯誤,主要是因為無法找到product-def.jar中定義的類。
我試圖打印出類路徑,如下所示
<property name="myclasspath" refid="project.class.path"/>
<echo message="${myclasspath}" />
輸出結果為c:\\product\\lib\\log4j-1.2.16.jar;c:\\product\\${product-def.jar}
以上表明以下定義不正確
<pathelement location="${product-def.jar}"/>
定義屬性文件中定義的路徑元素的正確方法是什么?
我認為問題在於,在將屬性文件加載到buildLive目標之前,已初始化project.class.path的定義。 有沒有一種方法可以將project.class.path的初始化延遲到buildLive目標完成之后?
有沒有一種方法可以將project.class.path的初始化延遲到buildLive目標完成之后?
將<path>
定義放在<target>
<target name="_initLiveProps">
<property file="buildscripts/live.properties"/>
<path id="project.class.path">
<pathelement location="./../lib/log4j-1.2.16.jar" />
<pathelement location="${product-def.jar}"/>
</path>
</target>
<path>
對於所有(直接或間接)依賴於此目標的目標都是可見的。
如果您有幾個加載不同屬性的不同目標,例如_initLiveProps
, _initDevProps
等,則可以將<path>
定義放入一個通用目標,如下所示
<target name="classpath">
<path id="project.class.path">
<pathelement location="./../lib/log4j-1.2.16.jar" />
<pathelement location="${product-def.jar}"/>
</path>
</target>
<target name="_loadLiveProps">
<property file="buildscripts/live.properties"/>
</target>
<target name="_initLiveProps" depends="_loadLiveProps, classpath" />
<target name="_loadDevProps">
<property file="buildscripts/dev.properties"/>
</target>
<target name="_initDevProps" depends="_loadDevProps, classpath" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.