Ant 1.7.1 and package-info.java compilation problem of JAX-WS generated classes

Today 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:

  1. Generate class calling wsconsume
  2. compile them and its client using ant and run my test perfectly working
  3. 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:

  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 <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 :P

12 Responses to “Ant 1.7.1 and package-info.java compilation problem of JAX-WS generated classes”

  1. Jeff says:

    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.

  2. Angus says:

    Me too, after upgrading eclipse from Ganymede to Galileo.
    why can’t they just compile the package-info anyway? :-(
    Thanks a million.

  3. Anatoli Peretoltchine says:

    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.

  4. Dean McNabb says:

    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.

  5. Sundar says:

    Thanks, I struggled to find this for 1.5 days.

  6. Wam says:

    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.

  7. Yep you are right. Post fixed.

  8. Jens says:

    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 ‘>’.

  9. Jens says:

    The comment facility did not allow me to include XML elements…

    I had to include an additional sleep call.

  10. Tess says:

    Thanks, Stefano. I ran into the exact same issue as Jeff while using JAXB’s xjc compiler with Ant. And thanks, Jens, for the sleep tip. Everybody’s comments saved me many hours of work.

  11. Carsten Clark says:

    Stefano, you solved a mystery that had been plaguing me for a year. Mille grazie for making this info public!

  12. Bhaskara says:

    Thanks a lot.. I was breaking my head for last 2 days… and ur solution worked like a magic… thanks again

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>