2010-04-07 30 views
4

鑑於這種ant腳本:的NullPointerException在com.sun.tools.jxc.SchemaGenTask

<?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> 

我收到此錯誤:

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 

任何想法?

回答

0

<schemagen>任務需要包含一個類路徑,可能相當於<javac>任務中的內容,毫無疑問,該任務位於Ant腳本的其他位置。我也在質疑srcdir屬性的價值。它應該指向源代碼樹的頂部,而不是在任何包中。它看起來像「gb.informaticasystems.messages」可能是你的項目中的一個包。如果是這樣,您應該將屬性更改爲srcdir="src"。因此,它應該是這個樣子(您需要提供類路徑):

<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> 
+0

不是這樣,但它確實讓我看到了指向我JDK版本的Java Bug Parade。我從運行ant腳本1.6開始切換到1.5,然後導致*正確的堆棧跟蹤被拋出,並從那裏解決了問題。謝謝。 – 2010-04-08 13:46:43

+0

太棒了!也許你可以自己提交答案,以防其他人遇到類似問題的Stack Overflow。 – 2010-04-08 15:23:34

0

我從運行1.6 Ant腳本到1.5,然後引起適當的堆棧切換跟蹤拋出並從那裏我固定問題。

+0

你能詳細說明你的問題/解決方案是什麼嗎?我在classpath中的所有類都編譯爲1.6 ... – Stephen 2010-07-07 04:36:20

3

我有這個問題,因爲我的srcdir被設置爲包含java文件的包文件夾。

將此更改爲頂級源文件夾效果更好,但是然後schemagen想爲我的源路徑上的所有.java文件(僅20%實際上是jaxb類)創建架構。

我最後的螞蟻呼叫的樣子:

<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> 
0

原因這個錯誤很可能是一些類是被從要創建一個模式類使用失蹤。 在我的情況下,我不得不包含一些沒有出現在我的第一組匹配通配符中的缺失類。我使用過Maven,並且必須從jaxb2-maven-plugin版本1.6切換到1.5,在verbose設置爲true時顯示一些錯誤。後來我轉回到最新版本。

    <execution> 
        <phase>generate-resources</phase> 
        <id>rest-webservice-schemagen</id> 
        <goals> 
         <goal>schemagen</goal> 
        </goals> 
        <configuration> 
         <includes> 
          <include>**/*DTO.java</include> 
          <include>**/*Type.java</include> 
          <include>**/*Status.java</include> 
         </includes> 
         <verbose>true</verbose> 
        </configuration> 
       </execution> 
相關問題