使用jaxb schemagen创建XSD

时间:2010-11-29 16:37:42

标签: java xsd jaxb2

我正在学习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的类路径。

提前致谢

Umesh制作

1 个答案:

答案 0 :(得分:0)

您似乎已将类的包声明设置为

com.tr.model.address  

它应该来自您的目录结构

com.tr.model.destination