Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant: Convert class name to file path

Tags:

ant

How do I convert Java class names into file paths using Ant tasks?

For example, given a property containing foo.bar.Duck I'd like to get out foo/bar/Duck.class.

I tried (and failed) to implement this in terms of <pathconvert> and <regexpmapper>.

like image 536
Gili Avatar asked Feb 03 '12 17:02

Gili


1 Answers

Here's a possible way to do this:

<property name="class.name" value="foo.bar.Duck"/>

<loadresource property="file.name">
  <string value="${class.name}" />
  <filterchain>
    <replaceregex pattern="\." replace="/" flags="g" />
    <replaceregex pattern="$" replace=".class" />
  </filterchain>
</loadresource>

This puts the desired foo/bar/Duck.class into the file.name property.

like image 106
matt Avatar answered Oct 02 '22 18:10

matt