我正在学习JAXb 2.0,并且是它的新手。

我正在尝试使用schemagen基于y POJO类生成XSD,对于简单的类,它工作正常,但是当我的类包含对其他类的引用时

schemagen给我以下错误是相同的错误跟踪

注释处理期间遇到的问题;
有关更多信息,请参见下面的stacktrace。

java.lang.NullPointerException
        at com.sun.tools.jxc.model.nav.APTNavigator$2.onDeclaredType(APTNavigator.java:436)
        at com.sun.tools.jxc.model.nav.APTNavigator$2.onClassType(APTNavigator.java:410)
        at com.sun.tools.jxc.model.nav.APTNavigator$2.onClassType(APTNavigator.java:464)
        at com.sun.istack.tools.APTTypeVisitor.apply(APTTypeVisitor.java:27)
        at com.sun.tools.jxc.model.nav.APTNavigator.getBaseClass(APTNavigator.java:113)
        at com.sun.tools.jxc.model.nav.APTNavigator.getBaseClass(APTNavigator.java:89)
        at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.getIndividualType(PropertyInfoImpl.java:195)
        at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.<init>(PropertyInfoImpl.java:137)
        at com.sun.xml.bind.v2.model.impl.MapPropertyInfoImpl.<init>(MapPropertyInfoImpl.java:71)
        at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.createMapProperty(ClassInfoImpl.java:928)
        at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.addProperty(ClassInfoImpl.java:885)
        at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.findGetterSetterProperties(ClassInfoImpl.java:1004)
        at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.getProperties(ClassInfoImpl.java:314)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:247)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:213)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:319)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:334)
        at com.sun.tools.xjc.api.impl.j2s.JavaCompilerImpl.bind(JavaCompilerImpl.java:94)
        at com.sun.tools.jxc.apt.SchemaGenerator$1.process(SchemaGenerator.java:119)
        at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.process(AnnotationProcessors.java:60)
        at com.sun.tools.apt.comp.Apt.main(Apt.java:454)
        at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java:258)
        at com.sun.tools.apt.main.Main.compile(Main.java:1102)
        at com.sun.tools.apt.main.Main.compile(Main.java:964)
        at com.sun.tools.apt.Main.processing(Main.java:95)
        at com.sun.tools.apt.Main.process(Main.java:85)
        at com.sun.tools.apt.Main.process(Main.java:67)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.tools.jxc.SchemaGenerator$Runner.main(SchemaGenerator.java:245)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.tools.jxc.SchemaGenerator.run(SchemaGenerator.java:177)
        at com.sun.tools.jxc.SchemaGenerator.run(SchemaGenerator.java:81)
        at com.sun.tools.jxc.SchemaGenerator.main(SchemaGenerator.java:73)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.tools.jxc.SchemaGeneratorFacade.main(SchemaGeneratorFacade.java:60)
C:\Users\Desktop\jaxb\jaxb-ri-20101119\bin\src\com\tr\model\destination\Destination.java:9: package com.tr.model.address does not exist
import com.tr.model.address.BasicAddress;[code]


下面是我的文件夹结构的详细信息

schemagen位于以下位置

C:\Users\Desktop\jaxb\jaxb-ri-20101119\bin


我试图生成xsd的Java类位于以下位置

C:\Users\Desktop\jaxb\jaxb-ri-20101119\bin\src\com\tr\model\destination


Destination.java

而所有其他从Destination引用的类以及该类本身都在以下结构内

C:\Users\Raisonne\Desktop\jaxb\jaxb-ri-20101119\bin\src\com\raisonne\tr\model


我知道问题出在类路径的设置上,但我无法弄清楚如何为这种情况设置正确的类路径

我试图将系统的CLASSPATH变量设置为的值

C:\Users\Raisonne\Desktop\jaxb\jaxb-ri-20101119\bin\src\com\raisonne\tr\model as well other 2 mentioned in my post but nothing worked out.


谁能帮我设置schemagen的类路径。

提前致谢

乌梅什

最佳答案

看来您已经将类的包声明设置为

com.tr.model.address


它应该在您的目录结构中

com.tr.model.destination

07-27 22:07