开发者

Ant path convert

Good afternoon

I am running ant to process some code now I have path "com/source/project" in properties but I need to pass "com.source.project" to my java code is there anyway I can convert "/" to "." usin开发者_JAVA百科g ant command

thanks


PropertyRegex task works for you, but you need to install 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>


Here's some complete project that uses the Ant Plugin Flaka. I also had to replace the ${path.separator} with '.' to start some java classes. See the comments starting with ';'

<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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜