Ant 1.7.1 and package-info.java compilation problem of JAX-WS generated classes
March 16, 2009 – 4:27 pm by Stefano MAESTRIToday I have spent a lot of time with a very strange issue compiling JAX-WS generated classes. I have been using jbossws wsconsume to generate some classes from a .NET wsdl and I had a very strange behaviour:
- Generate class calling wsconsume
- compile them and its client using ant and run my test perfectly working
- then calling my clean task to remove .class files and recompile them and run my tests doesn’t work!
IOW JAX-WS client have been working only the first time I compile them. I couldn’t figure out why it have been working in that manner, but after a lot of google search I got this commit. In practice what have been happening is better described in “Note on package-info.java” paragraph of javac target in ant manual. Starting from version 1.7.1 ant compile package-info.java only in these 3 case:
- If a
package-info.classfile exists and is older than thepackage-info.javafile. - If the directory for the
package-info.classfile does not exist. - If the directory for the
package-info.classfile exists, and has an older modification time than the thepackage-info.javafile. In this case <javac> will touch the corresponding .class directory on successful compilation.
In practice if you havea ant task like mine:
<target name=”compile” depends=”init” description=”Compile the Java source code”>
<javac destdir=”${classes.dir}” classpathref=”build.classpath” debug=”${javac.debug}” deprecation=”${javac.deprecation}” target=”1.5″>
<src path=”${src.java.dir}” />
</javac>
Here the compilation target compile all files and so create directory where package-info.class will be contained during other generated files compilation. In this case the compilation target never re-generate package-info.class because no one of the 3 conditions is true. My workaround have been to change my build.xml file and have this compile target:
<target name=”compile” depends=”init” description=”Compile the Java source code”>
<touch>
<fileset dir=”${src.java.dir}” includes=”**/package-info.java”/>
</touch>
<javac destdir=”${classes.dir}” classpathref=”build.classpath” debug=”${javac.debug}” deprecation=”${javac.deprecation}” target=”1.5″>
<src path=”${src.java.dir}” />
</javac>
Hoping this post would be useful for someone, let me remark that is a problem of ant javac task, not of jbossws and you will get the same problem with any other jaxws stack.
Let me remark also that Wise perfectly work in this case regenerating it’s classes on the fly ![]()













9 Responses to “Ant 1.7.1 and package-info.java compilation problem of JAX-WS generated classes”
I got bit by this one just yesterday too, but from a slightly different angle. I am using JAXB-annotated classes (and invoking schemagen from ant). When I started building with Ant 1.7.1 instead of 1.7.0, the JAXB deserialization of my XML in the code was failing even though I had not touched any of the code. Debugging showed that somehow only the local element names for the annotated classes were populated (no namespace URIs). It took me several hours to figure out that Ant had not been compiling the package-info classes into my jar, which are needed to get the namespace URIs associated with the packages.
By Jeff on Jun 17, 2009
Me too, after upgrading eclipse from Ganymede to Galileo.
why can’t they just compile the package-info anyway?
Thanks a million.
By Angus on Sep 3, 2009
Thanks Stefano!
You saved my day. I had the same problem as Jeff with my jaxb-ri generated schema and it took me a couple of hours to figure out that package-info.class had not been compiled. Your post explained well why that happened.
By Anatoli Peretoltchine on Sep 11, 2009
Thanks for this. I spent 1.5 days trying to work out what was going wrong. I was using Netbeans to generate the wsit configuration and classes, then switching over to eclipse and using ant to build my application.
By Dean McNabb on Oct 11, 2009
Thanks, I struggled to find this for 1.5 days.
By Sundar on Oct 29, 2009
Thanx for the tip but I can not see any difference between the two ant tasks… I suppose it should be the touch but, to be confirmed please.
By Wam on Nov 25, 2009
Yep you are right. Post fixed.
By Stefano MAESTRI on Nov 25, 2009
Thanks a lot for your tip, especially for the link to the commit.
I had to include an additional
between the touch and the javac command. This was neccessary because my target directory was created just before calling touch. Therefore the lastmodified value of the target directory and my package-info.java file where identical. The javac-task does not compare using ‘>=’, but ‘>’.
By Jens on Feb 15, 2010
The comment facility did not allow me to include XML elements…
I had to include an additional sleep call.
By Jens on Feb 15, 2010