Odd behaviour using Ant + JAXB

Using, IDEA 9.0.1, Java 6_14, JAXB 2.1

So I'm not using the JAXB integration built-in to Intellij.   I've got my project's lib/jaxb folder and it contains:

activation.jar
jaxb-api.jar
jaxb-impl.jar
jaxb-xjc.jar
jaxb1-impl.jar
jsr173_1.0_api.jar

which I think I recall is just the contents of downloading the RI from dev.java.net.

I also use my own Ant file to do building, and what I've got there (in part) is:

    <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
        <classpath>
            <fileset dir="${lib.dir}/jaxb" includes="*.jar" />
        </classpath>
    </taskdef>


    <target name="jaxb">

        <xjc schema="schema/BillingReport.xsd"
             binding="schema/bindings.xjb"
             extension="true"
             destdir="${src.dir}"
             package="${jaxb.gen.package}.Billing"
             readonly="true"
             removeOldOutput="true">
            <produces dir="${jaxb.gen.directory}/Billing" includes="**/*.java" />
        </xjc>
        .
        .
        .
    </target>


Ok, what I'm seeing is that the taskdef element has a red squiggle (just under the word taskdef) and the error tooltip is that "Failed to load type(s): com.sun.tools.xjc.XJCTask".  And then, each of my <xjc elements is yellow highlighted (just the word xjc) and it's tootip is "Using definition which type failed to load"  (which is a  bit of engrish - s/b Using definition whose type failed to load, but that's not important).

However.... I can right click the jaxb target and run it. I assume that's because the Ant task is being invoked with IDEA's project library settings, which includes the lib/jaxb directory, which includes jaxb-xjc.jar.  Because as I understand it, the JDK itself doesn't ship with the xjc task jar file.  So maybe it's just the editor for Ant files that isn't somehow finding that jar file in the project dir.   And this makes me think of other tasks, and having to put the jar files for those into IDEA's embedded Ant/lib directory.

So, I then copied jaxb-xjc.jar into $IDEA_HOME/lib/ant/lib and restarted.   The red squiggle is gone from the taskdef. But now I have way more red squiggles.

For all attributes and elements on all <xjc tasks,  it has a red squiggle underneath and the same message "attribute foo is not allowed here", and for the <produces element, it's "element produces is not defined".  And now, if I try to run the task, I get:


~/projects/myproject/code/build.xml:39: java.lang.NoClassDefFoundError: com/sun/xml/bind/api/ErrorListener
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
     at org.apache.tools.ant.Task.perform(Task.java:348)
     at org.apache.tools.ant.Target.execute(Target.java:357)
     at org.apache.tools.ant.Target.performTasks(Target.java:385)
     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
     at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
     at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
     at org.apache.tools.ant.Main.runBuild(Main.java:758)
     at org.apache.tools.ant.Main.startAnt(Main.java:217)
     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:32)
Caused by: java.lang.NoClassDefFoundError: com/sun/xml/bind/api/ErrorListener
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
     at java.lang.ClassLoader.defineClass(ClassLoader.java:466)
     at com.sun.istack.tools.ParallelWorldClassLoader.findClass(ParallelWorldClassLoader.java:90)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
     at java.lang.ClassLoader.defineClass(ClassLoader.java:466)
     at com.sun.istack.tools.ParallelWorldClassLoader.findClass(ParallelWorldClassLoader.java:90)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
     at java.lang.Class.getDeclaredConstructors0(Native Method)
     at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
     at java.lang.Class.getConstructor0(Class.java:2699)
     at java.lang.Class.newInstance0(Class.java:326)
     at java.lang.Class.newInstance(Class.java:308)
     at com.sun.istack.tools.ProtectedTask.execute(ProtectedTask.java:49)
     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
     ... 16 more



So, I can just remove that jar file I put into Ant's lib folder.  And I get the "less red squiggles" version.  But I'd like to know what's wrong and how to fix it.

2 comments
Comment actions Permalink

Me too, I'm having the same problem.  Is this a bug, I wonder?  The build file actually works fine, but I'd like to stop seeing red.

0
Comment actions Permalink

I know this is an old thread, but since the answer isn't on here and it is what comes up in the search, I thought I'd update it as I came across this problem today.

Basically, from http://youtrack.jetbrains.net/issue/IDEA-11248#comment=27-57354, if you use XJC2Task in the taskdef IDEA can resolve the properties.
XJCTask delegates to XJC2Task when you are using JAXB2.

0

Please sign in to leave a comment.