2013-12-13 28 views
0

我的問題是道路,我必須建立從路徑清單項類路徑就像使用螞蟻清單路徑條目從建築物的依賴罐子

  • C:\用戶\ rosansamuel.ivy2 \緩存\ log4j的\ log4j \ jars \ log4j-1.2.14.jar

你可以請任何人提出一些建議嗎?

下面的代碼是,我想用propertyregex,但實際上我無法獲得罐子名稱。

<for list="${ofsml.manifest.classpath.list}" delimiter=";" param="individual.path"> 
    <sequential> 
    <property name="single.artifact.path" value="@{individual.path}"/> 
    <echo message="single aritfact path name : ${single.artifact.path}"/> 
    <path id="my.base.path"> 
     <pathelement path="${single.artifact.path}"/> 
    </path> 
    <property name="artifact.id.file" refid="my.base.path"/> 
    <echo message=" artifact.id.file: ${artifact.id.file}"/> 
    <propertyregex property="artifact.id" input="${artifact.id.file}" regexp=".*.jar" select="\1"/> 
    <echo message="jar name : ${artifact.id}"/> 
    <echo message="individual.path = @{individual.path}"/> 
    </sequential> 
</for> 
+0

不明白你在問什麼,但似乎就像你只需要從絕對文件路徑獲取文件名一樣?!爲此目的有一個任務。另外,當使用\ 1您的正則表達式應該有一個組,f.e. 。+ \\(。+ jar)表示\ 1會從C:\ Users \ rosansamuel.ivy2 \ cache \ log4j \ log4j \ jars \ log4j-1.2.14.jar中捕獲log4j-1.2.14.jar – Rebse

+0

嗨Mate,是的,你是對的。我的要求是從路徑中單獨提取jar名稱。但我有路徑列表。 – androidgalaxyman

回答

0

有在ANT一個manifestclasspath任務,可以生成一個文件集相關文件路徑的列表。

我也看到你正在使用ivy,爲什麼不使用它的retrieve任務來將你的依賴jar放在與你正在構建的jar相關的本地目錄中。否則,你的jar將被硬編碼,以期望它的依賴是一個在你的機器上運行的絕對路徑,但不是很便攜。

這裏是一個小片段:

<target name="build" depends="compile"> 
    <ivy:retrieve pattern="${dist.dir}/lib/[artifact].[ext]"/> 

    <manifestclasspath property="jar.classpath" jarfile="${dist.jar}"> 
     <classpath> 
     <fileset dir="${dist.dir}/lib" includes="*.jar"/> 
     </classpath> 
    </manifestclasspath> 

    <jar destfile="${dist.jar}" basedir="${build.dir}/classes"> 
     <manifest> 
     <attribute name="Main-Class" value="${dist.main.class}"/> 
     <attribute name="Class-Path" value="${jar.classpath}"/> 
     </manifest> 
    </jar> 
    </target> 

更完整的示例,請參見: