Women in Technology

Hear us Roar

  Enums in Java (One More Time)
Subject:   Using Ant to Translate ".enum" Files
Date:   2003-05-06 10:41:28
From:   jimoore
I recently received the following email from Brian Agnew:

> Just read your O'Reilly article on enums in Java. I liked your
> solution of automatically creating enum definitions via a .enum
> file. A thought however! Have you looked at writing an Ant
> task to invoke the compiler?

Great idea, Brian! Actually I am fairly new to Ant, and I hadn't thought of it before, but I have placed a revised version of the jEnum.zip file on the article's web site that has this capability. I had to modify the translator slightly to make things work, but that may have just been a problem with my understanding of Ant. FYI, the Ant task that does the work looks like the following:

<!-- run the jEnum translator the jEnum files -->
<target name="enum">
<apply executable="java" dest="${src.dir}">
<arg value="-jar"/>
<arg file="${lib.dir}/jEnum.jar"/>
<arg value="-o"/>
<fileset dir="${src.dir}">
<include name="**/*.enum"/>
<mapper type="glob" from="*.enum" to="*.java"/>