使用jaxb-ri-2.2.7在ant schemagen任务中的ClassCastException

时间:2014-07-08 12:26:14

标签: java xml ant jaxb schemagen

我正在尝试使用来自JAXB-RI 2.2.7的schemagen ant任务,但我在build.xml中的schemagen任务上不断获得“BUILD FAILED .... Error ap ap”。相关的节如下:

<taskdef name="schemagen" classname="com.sun.tools.jxc.SchemaGenTask">
  <classpath refid="compile.classpath"/>
</taskdef>

<target name="schemas" description="Compile all Java source files">
 <mkdir dir="${schemas.dir}" />
 <schemagen destdir="${schemas.dir}">
  <src path="${src.dir}"/>
  <classpath refid="compile.classpath" />
 </schemagen>
</target>

使用-verbose,我得到下面的堆栈跟踪。我试过谷歌搜索ClassCastException的细节但没有找到任何东西。有什么建议?

谢谢,亚当

BUILD FAILED
/home/adam/sandboxes/adam/sensei/code/trunk/repository/build.xml:99: Error starting ap
    at com.sun.tools.jxc.ApBasedTask$InternalApAdapter.execute(ApBasedTask.java:131)
    at com.sun.tools.jxc.ApBasedTask.compile(ApBasedTask.java:170)
    at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:930)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.Main.runBuild(Main.java:851)
    at org.apache.tools.ant.Main.startAnt(Main.java:235)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.RuntimeException: java.lang.AssertionError: java.lang.ClassCastException: com.sun.tools.javac.api.JavacTrees cannot be cast to com.sun.source.util.Trees
    at com.sun.tools.javac.main.Main.compile(Main.java:469)
    at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
    at com.sun.tools.jxc.ApBasedTask$InternalApAdapter.execute(ApBasedTask.java:127)
    ... 18 more
Caused by: java.lang.AssertionError: java.lang.ClassCastException: com.sun.tools.javac.api.JavacTrees cannot be cast to com.sun.source.util.Trees
    at com.sun.source.util.Trees.getJavacTrees(Trees.java:84)
    at com.sun.source.util.Trees.instance(Trees.java:73)
    at com.sun.tools.jxc.model.nav.ApNavigator.getClassLocation(ApNavigator.java:410)
    at com.sun.tools.jxc.model.nav.ApNavigator.getClassLocation(ApNavigator.java:83)
    at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.getLocation(ClassInfoImpl.java:1284)
    at com.sun.xml.bind.v2.runtime.IllegalAnnotationException.convert(IllegalAnnotationException.java:122)
    at com.sun.xml.bind.v2.runtime.IllegalAnnotationException.build(IllegalAnnotationException.java:106)
    at com.sun.xml.bind.v2.runtime.IllegalAnnotationException.<init>(IllegalAnnotationException.java:70)
    at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.<init>(ClassInfoImpl.java:211)
    at com.sun.xml.bind.v2.model.impl.ModelBuilder.createClassInfo(ModelBuilder.java:399)
    at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:257)
    at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:227)
    at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:375)
    at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:390)
    at com.sun.tools.jxc.api.impl.j2s.JavaCompilerImpl.bind(JavaCompilerImpl.java:95)
    at com.sun.tools.jxc.ap.SchemaGenerator.process(SchemaGenerator.java:110)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
    at com.sun.tools.javac.main.Main.compile(Main.java:439)
    ... 20 more
Caused by: java.lang.ClassCastException: com.sun.tools.javac.api.JavacTrees cannot be cast to com.sun.source.util.Trees
    at com.sun.source.util.Trees.getJavacTrees(Trees.java:82)
    ... 43 more

1 个答案:

答案 0 :(得分:0)

这里的问题相同。从堆栈跟踪中我会说它在JAXB注释中有一些错误,但是当xjc尝试处理该异常时,它会失败并且另一个异常,并且无法知道问题所在的类和属性。