users@jaxb.java.net

RE: "ClassTypeImpl cannot be cast to com.sun.mirror.type.AnnotationType" on schemagen

From: KARR, DAVID (ATTCINW) <"KARR,>
Date: Thu, 7 Jan 2010 11:40:46 -0800

> -----Original Message-----
> From: KARR, DAVID (ATTCINW)
> Sent: Wednesday, January 06, 2010 3:17 PM
> To: users_at_jaxb.dev.java.net
> Subject: "ClassTypeImpl cannot be cast to
> com.sun.mirror.type.AnnotationType" on schemagen
>
> I've been working on an app using CXF/JAXB/OpenJPA for a few weeks. I
> had added the "schemagen" task work a while ago, and I was able to
> generate the schema. Recently I tried doing it again, and I'm seeing
> exceptions like the following:

I've resolved this problem. The key is that setting the classpath in
the "taskdef" is not the same as the embedded classpath in the task
instance. Once I set the correct classpath in the embedded classpath in
the task instance, I was able to get it to work.

> ------------------------
> Generating schema from 48 source files
> error: Could not create declaration for annotation type Strategy
> error: Could not create declaration for annotation type OrderColumn
> error: Could not create declaration for annotation type Temporal
> error: Could not create declaration for annotation type OneToMany
> error: Could not create declaration for annotation type Column
> error: Could not create declaration for annotation type Basic
> error: Could not create declaration for annotation type OneToOne
> error: Could not create declaration for annotation type Id
> error: Could not create declaration for annotation type IdClass
> error: Could not create declaration for annotation type Entity
> Problem encountered during annotation processing;
> see stacktrace below for more information.
> java.lang.ClassCastException:
> com.sun.tools.apt.mirror.type.ClassTypeImpl cannot be cast to
> com.sun.mirror.type.AnnotationType
> at
>
com.sun.tools.apt.mirror.declaration.AnnotationMirrorImpl.getAnnotation
> T
> ype(AnnotationMirrorImpl.java:82)
> at
>
com.sun.tools.jxc.apt.InlineAnnotationReaderImpl.getAllAnnotations(Inli
> n
> eAnnotationReaderImpl.java:113)
> at
>
com.sun.tools.jxc.apt.InlineAnnotationReaderImpl.getAllFieldAnnotations
> (
> InlineAnnotationReaderImpl.java:88)
> at
>
com.sun.tools.jxc.apt.InlineAnnotationReaderImpl.getAllFieldAnnotations
> (
> InlineAnnotationReaderImpl.java:64)
> at
>
com.sun.xml.bind.v2.model.impl.ClassInfoImpl.findFieldProperties(ClassI
> n
> foImpl.java:371)
> at
>
com.sun.xml.bind.v2.model.impl.ClassInfoImpl.getProperties(ClassInfoImp
> l
> .java:301)
> at
>
com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.j
> a
> va:243)
> at
>
com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.j
> a
> va:209)
> at
>
com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.ja
> v
> a:315)
> at
>
com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.ja
> v
> a:330)
> at
>
com.sun.tools.xjc.api.impl.j2s.JavaCompilerImpl.bind(JavaCompilerImpl.j
> a
> va:90)
> at
>
com.sun.tools.jxc.apt.SchemaGenerator$1.process(SchemaGenerator.java:11
> 5
> )
> at
>
com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.pr
> o
> cess(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(NativeMethodAccessorImpl.ja
> v
> a:39)
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
> r
> Impl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
>
com.sun.tools.jxc.AptBasedTask$InternalAptAdapter.execute(AptBasedTask.
> j
> ava:97)
> at com.sun.tools.jxc.AptBasedTask.compile(AptBasedTask.java:144)
> at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:882)
> at
> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
> at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
> r
> Impl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
>
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:
> 1
> 06)
> at org.apache.tools.ant.Task.perform(Task.java:348)
> at org.apache.tools.ant.Target.execute(Target.java:357)
> at org.apache.tools.ant.Target.performTasks(Target.java:385)
> at
> org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
> at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
> at
>
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecu
> t
> or.java:41)
> at
> org.apache.tools.ant.Project.executeTargets(Project.java:1189)
> at org.apache.tools.ant.Main.runBuild(Main.java:758)
> at org.apache.tools.ant.Main.startAnt(Main.java:217)
> at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
> at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
> -----------------
>
> My domain classes that have the "@Xml..." annotations also have
> JPA-related annotations on them (like "Entity", "Id", etc.).
>
> I'm not having trouble compiling and executing this code, I'm just
> unable to generate the schema.
>
> From my searches, it appears that other people have run into this. In
> fact, it appears to be the presence of the non-JAXB annotations that
> causes this problem. It's not really practical to remove the non-JAXB
> annotations.
>
> Is there any other easier workaround for this problem?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net