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:
- 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 ![]()
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.
Me too, after upgrading eclipse from Ganymede to Galileo.
why can’t they just compile the package-info anyway?
Thanks a million.
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.
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.
Thanks, I struggled to find this for 1.5 days.
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.
Yep you are right. Post fixed.
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 ‘>’.
The comment facility did not allow me to include XML elements…
I had to include an additional sleep call.
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.
Stefano, you solved a mystery that had been plaguing me for a year. Mille grazie for making this info public!
Thanks a lot.. I was breaking my head for last 2 days… and ur solution worked like a magic… thanks again