tags:

views:

257

answers:

3

Given this ant script:

<?xml version="1.0" encoding="UTF-8"?>
<project name="projectname" default="generate-schema" basedir=".">

    <taskdef name="schemagen" classname="com.sun.tools.jxc.SchemaGenTask">
        <classpath>
            <fileset dir="../BuildJars/lib" includes="*.jar" />
        </classpath>
    </taskdef>

    <target name="generate-schema">
        <schemagen srcdir="src/gb/informaticasystems/messages" destdir="schema">
            <schema namespace="http://www.informatica-systems.co.uk/aquarius/messages/1.0" file="messages-1.0.xsd" />
        </schemagen>
    </target>

</project>

I am getting this error:

Buildfile: C:\Users\davidcollie\workspace\aquarius-feature\AquariusServerLibrary\schemagen.xml
generate-schema:
[schemagen] Generating schema from 4 source files
[schemagen] Problem encountered during annotation processing; 
[schemagen] see stacktrace below for more information.
[schemagen] java.lang.NullPointerException
[schemagen]     at com.sun.tools.jxc.model.nav.APTNavigator$2.onDeclaredType(APTNavigator.java:428)
[schemagen]     at com.sun.tools.jxc.model.nav.APTNavigator$2.onClassType(APTNavigator.java:402)
[schemagen]     at com.sun.tools.jxc.model.nav.APTNavigator$2.onClassType(APTNavigator.java:456)
[schemagen]     at com.sun.istack.tools.APTTypeVisitor.apply(APTTypeVisitor.java:27)
[schemagen]     at com.sun.tools.jxc.model.nav.APTNavigator.getBaseClass(APTNavigator.java:109)
[schemagen]     at com.sun.tools.jxc.model.nav.APTNavigator.getBaseClass(APTNavigator.java:85)
[schemagen]     at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.getIndividualType(PropertyInfoImpl.java:190)
[schemagen]     at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.<init>(PropertyInfoImpl.java:132)
[schemagen]     at com.sun.xml.bind.v2.model.impl.MapPropertyInfoImpl.<init>(MapPropertyInfoImpl.java:67)
[schemagen]     at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.createMapProperty(ClassInfoImpl.java:917)
[schemagen]     at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.addProperty(ClassInfoImpl.java:874)
[schemagen]     at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.findGetterSetterProperties(ClassInfoImpl.java:993)
[schemagen]     at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.getProperties(ClassInfoImpl.java:303)
[schemagen]     at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:243)
[schemagen]     at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:209)
[schemagen]     at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:315)
[schemagen]     at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:330)
[schemagen]     at com.sun.tools.xjc.api.impl.j2s.JavaCompilerImpl.bind(JavaCompilerImpl.java:90)
[schemagen]     at com.sun.tools.jxc.apt.SchemaGenerator$1.process(SchemaGenerator.java:115)
[schemagen]     at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.process(AnnotationProcessors.java:60)
[schemagen]     at com.sun.tools.apt.comp.Apt.main(Apt.java:454)
[schemagen]     at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java:258)
[schemagen]     at com.sun.tools.apt.main.Main.compile(Main.java:1102)
[schemagen]     at com.sun.tools.apt.main.Main.compile(Main.java:964)
[schemagen]     at com.sun.tools.apt.Main.processing(Main.java:95)
[schemagen]     at com.sun.tools.apt.Main.process(Main.java:85)
[schemagen]     at com.sun.tools.apt.Main.process(Main.java:67)
[schemagen]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[schemagen]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[schemagen]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[schemagen]     at java.lang.reflect.Method.invoke(Method.java:597)
[schemagen]     at com.sun.tools.jxc.AptBasedTask$InternalAptAdapter.execute(AptBasedTask.java:97)
[schemagen]     at com.sun.tools.jxc.AptBasedTask.compile(AptBasedTask.java:144)
[schemagen]     at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:820)
[schemagen]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[schemagen]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[schemagen]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[schemagen]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[schemagen]     at java.lang.reflect.Method.invoke(Method.java:597)
[schemagen]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[schemagen]     at org.apache.tools.ant.Task.perform(Task.java:348)
[schemagen]     at org.apache.tools.ant.Target.execute(Target.java:357)
[schemagen]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
[schemagen]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[schemagen]     at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[schemagen]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[schemagen]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[schemagen]     at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[schemagen]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[schemagen]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

BUILD FAILED
C:\Users\davidcollie\workspace\aquarius-feature\AquariusServerLibrary\schemagen.xml:11: schema generation failed

Total time: 1 second

Any ideas?

A: 

The <schemagen> task needs to include a classpath, probably the equivalent to what's in the <javac> task that, no doubt, lives somewhere else in your Ant script. I'm also questioning the value of the srcdir attribute. It should point to the top of your source tree, and not within any packages. It looks to me like "gb.informaticasystems.messages" might be a package in your project. If so, you should change the attribute to srcdir="src". So, it should look something like this (you need to supply the classpath):

<target name="generate-schema">
    <schemagen srcdir="src" destdir="schema">
        <schema namespace="http://www.informatica-systems.co.uk/aquarius/messages/1.0" file="messages-1.0.xsd" />
        <classpath>
           <!-- Classpath definition goes here -->
        </classpath>
    </schemagen>
</target>
Rob Heiser
Not quite it but it did get me looking at the Java Bug Parade which pointed me at the version of the JDK. I switched from running the ant script from 1.6 to 1.5 which then caused *proper* stack traces to be thrown and from there I fixed the problem. Thanks.
David Collie
Great! Maybe you could submit the answer yourself, just in case someone else comes to Stack Overflow with a similar question.
Rob Heiser
A: 

I switched from running the ant script from 1.6 to 1.5 which then caused proper stack traces to be thrown and from there I fixed the problem.

David Collie
Can you elaborate on what your problem/solution was? All my classes on the classpath are compiled to 1.6...
Stephen
A: 

I had this issue because my srcdir was set to the package folder which contained the java files.

Changing this to the top level source folder was better, but then schemagen wanted to make a schema for all .java files on my source path (only 20% were actually jaxb classes).

My final ant call looks like:

<property name="event.package" value="my/organisation/events"/>
<schemagen srcdir="${src.main.java.dir}" 
    destdir="META-INF/event-schema" 
    classpathref="build.classpath">
    <include name="${event.package}/Event1.java"/>
    <include name="${event.package}/Event2.java"/>
</schemagen>
Stephen