Tuesday, 27 October 2009

JAXB & Ant : package-info.java compilation problem of JAXB generated classes.

 package-info.class not generated

1.Generate the class
  xjc -p test.xsd -d C:/workspace/Test/src
2. Compile the project . package-info.class is generated.
3. Then call the clean task to remove .class files and rebuild the project. package-info.class is not generated.


Note on package-info.java from Ant Manual [http://ant.apache.org/manual/CoreTasks/javac.html]

 package-info.java files were introduced in Java5 to allow package level annotations. On compilation, if the java file does not contain runtime annotations, there will be no .class file for the java file. Up to Ant 1.7.1, when the task is run again, the task will try to compile the package-info java files again.

In Ant 1.7.1 the package-info.java will only be compiled if:

   1. If a package-info.class file exists and is older than the package-info.java file.
   2. If the directory for the package-info.class file does not exist.
   3. If the directory for the package-info.class file exists, and has an older modification time than the the package-info.java file. In this case will touch the corresponding .class directory on successful compilation.
  


Related Links
http://ant.apache.org/manual/CoreTasks/javac.html
http://article.gmane.org/gmane.comp.jakarta.ant.devel/52586
http://www.javalinux.it/wordpress/?p=261

1 comment:

James said...

I've done the following workaround. It implements the first option when package-info.java will be compiled

<copy todir="${classes.dir}">
     <fileset dir="${src.dir}" includes="**/package-info.java"/>
</copy>
<move todir="${classes.dir}" includeemptydirs="false">
     <fileset dir="${classes.dir}" includes="**/package-info.java"/>
     <mapper type="glob" from="*.java" to="*.class"/>
</move>
<touch millis="0">
     <fileset dir="${classes.dir}" includes="**/package-info.class"/>
</touch>