2011-06-08 154 views
2

下午好螞蟻路徑轉換

我運行螞蟻現在我有路徑屬性「COM /源/項目」,以處理一些代碼,但我需要通過「com.source.project」我的Java代碼無論如何,我可以將「/」轉換爲「」。使用Ant命令

感謝

回答

3

PropertyRegex任務爲你工作,但你需要安裝ant-contrib

<project> 

<taskdef resource="net/sf/antcontrib/antcontrib.properties"> 
    <classpath> 
    <pathelement location="./ant-contrib-1.0b3.jar"/> 
    </classpath> 
</taskdef> 

<property name="path" value="com/source/project"/> 
<echo message="Path=${path}"/> 

<propertyregex property="java.package.name" 
       input="${path}" 
       regexp="/" 
       replace="." 
       global="true" 
       defaultValue="${path}" /> 

<echo message="package=${java.package.name}"/> 
</project> 
+0

感謝隊友! – Makky 2011-06-08 15:58:15

0

這是一些使用Ant Plugin Flaka的完整項目。我也不得不更換$ {} path.separator用「」啓動一些Java類。見先從意見「;」

<project xmlns:fl="antlib:it.haefelinger.flaka"> 

    <fl:install-property-handler/> 

    <property name="srcroot" value="path/to/srcrootdir"/> 
    <property name="classroot" value="path/to/classrootdir"/> 

    <!-- determine all main classes --> 
    <fileset dir="${srcroot}" includes="**/*.java" id="mainclasses"> 
    <contains text="public static void main"/> 
    </fileset> 

    <!-- iterate over those main classes and 
     call the corresponding classfile --> 
    <fl:for var="file" in="split('${toString:mainclasses}', ';')"> 
    <fl:let> 
     ; strip the .java Extension 
     file = replace(file, '', '.java') 
     ; replace fileseparator with '.' 
     ; on Windows you have to use the following line 
     ; replace(file, '\.', '${file.separator}${file.separator}') 
     file = replace(file, '\.', '${file.separator}') 
     </fl:let> 
    <fl:echo> 
     starting => #{file} in ${classroot} 
    </fl:echo> 
    <java classname="#{file}"> 
     <classpath> 
     <!-- 
     when using a fileset you'll get a 
     java.util.zip.ZipException because you're 
     referencing classfiles and no jars 
     therefore you have to use 
     pathelement and location 
     --> 
     <pathelement location="${classroot}"/> 
     </classpath> 
    </java> 
    </fl:for> 

</project> 
+0

我把它整理自己...但是我還是謝謝你:) – Makky 2011-06-10 08:24:27