XmlAdapter compile error

314 views
Skip to first unread message

kosaco

unread,
Dec 30, 2010, 4:54:10 AM12/30/10
to Google Web Toolkit
Hi!
In my gwt project, I use XmlAdapter class of the
javax.xml.bind.annotation.adapters package. When I'm compiling the
project, it has the follow error:

[ERROR] Line 11: No source code is available for type
javax.xml.bind.annotation.adapters.XmlAdapter<ValueType,BoundType>;
did you forget to inherit a required module?

I have the javax.xml.bin jar in my classpath and in the war/WEB-INF/
lib. Anyone have any idea to solve this problem?

Thanks

kosaco

unread,
Dec 30, 2010, 8:09:19 AM12/30/10
to Google Web Toolkit

ciosbel

unread,
Dec 30, 2010, 1:38:27 PM12/30/10
to Google Web Toolkit
I suppose you are trying to use that annotation on a client side
class; javax is not emulated by gwt compiler, so you couldn't use it
client side.

Why not moving the adapter to the server side? Does your client really
need it?
Annotated jaxb classes can be used by the client (with a couple of
tweaks and not for all annotations), but marshalling/unmarshalling to/
from xml, still need to be handled server side. In this point of view,
the adapter can be known only to your server.

I can tell you the tweak, but first try to move it server side.

shawnjohnson

unread,
Jun 20, 2012, 5:33:54 PM6/20/12
to google-we...@googlegroups.com
I am having this issue as well.  The annotations are in models in our 'shared' package - shared between client and server.  Anyone know what I should change to resolve this?

Andrea Boscolo

unread,
Jun 20, 2012, 6:16:03 PM6/20/12
to google-we...@googlegroups.com
Such annotations are not GWT compatible (i.e., they are not known to the GWT emulated JRE and definitely cannot be compiled in js, even providing the relative sources - that I think they can be found in jaxb-api-src.jar inside the jaxb distribution).
To allow jaxb annotations (and annotations only) to be used in client/shared side, you have to tell the gwt compiler to compile those classes ignoring such annotations while still allow the server side to use them.
See http://code.google.com/p/google-web-toolkit/issues/detail?id=4020#c8 for the workaround.

If you are using an XmlAdapter (the class) in client code, move it to server side (i.e., keep your marshalling/unmmarshalling logic in the server).

I assumed you are using GWT-RPC of course. With RequestFactory you should have no problem at all.

shawnjohnson

unread,
Jun 21, 2012, 7:35:05 AM6/21/12
to google-we...@googlegroups.com
Thank for the reply.  I'm only marshalling/unmarshalling on the server-side - so does that mean I should move those classes into a "server" package?  That's even if the annotation is in the shared bean?  Yes, still using GWT-RPC. Is the workaround as simple as this?

My.gwt.xml (before)
<module>
        <source path="common"/>
</module> <module>
<source path="common">
<exclude name="MyXmlAdapter1.java" />
<exclude name="MyXmlAdapter1.java" />
</source>

shawnjohnson

unread,
Jun 21, 2012, 7:38:40 AM6/21/12
to Google Web Toolkit
Sorry, I didn't mean to post that reply quite that way (hit some new
keyboard combo)...

My.gwt.xml
(before)
<module>
<source path="common"/>
</module>

(after)
<module>
<source path="common">
<exclude name="MyXmlAdapter1.java" />
<exclude name="MyXmlAdapter2.java" />
<exclude name="MyXmlAdapter2.java" />
</source>
</module>


On Jun 21, 7:35 am, shawnjohnson <shawnjohnson...@gmail.com> wrote:
> Thank for the reply.  I'm only marshalling/unmarshalling on the server-side
> - so does that mean I should move those classes into a "server" package?
>  That's even if the annotation is in the shared bean?  Yes, still using
> GWT-RPC. Is the workaround as simple as this?
>
> My.gwt.xml (before)
> <module>
>         <source path="common"/></module> <module> <source path="common">
> <exclude name="MyXmlAdapter1.java" />
> <exclude name="MyXmlAdapter1.java" />
> </source>
>
>
>
>
>
>
>
> On Wednesday, June 20, 2012 6:16:03 PM UTC-4, Andrea Boscolo wrote:
>
> > Such annotations are not GWT compatible (i.e., they are not known to the
> > GWT emulated JRE and definitely cannot be compiled in js, even providing
> > the relative sources - that I think they can be found in jaxb-api-src.jar
> > inside the jaxb distribution).
> > To allow jaxb annotations (and annotations only) to be used in
> > client/shared side, you have to tell the gwt compiler to compile those
> > classes ignoring such annotations while still allow the server side to use
> > them.
> > Seehttp://code.google.com/p/google-web-toolkit/issues/detail?id=4020#c8forthe workaround.

Andrea Boscolo

unread,
Jun 21, 2012, 3:28:07 PM6/21/12
to google-we...@googlegroups.com
If your classes are simply annotated with JAXB annotations, you should follow http://code.google.com/p/google-web-toolkit/issues/detail?id=4020 (comment 10) for the workaround, and keep them in the 'shared' package, so they can communicate and used with both sides (and you don't violate DRY).
But If you have adapters (i.e., classes that extend XmlAdapter<V, B>) that are in the client/shared side, you should move them in the server, 'cause they cannot be compiled and are useful only when taking marshalling/unmarshalling in account.
I don't think your solution work. You are only excluding files from compilation, but what if they are useful? Move adapters to the server. Keep annotated classes in the 'shared' and follow the above link.

Shawn Johnson

unread,
Jun 22, 2012, 10:02:53 AM6/22/12
to google-we...@googlegroups.com
Andrea - thank you so much.  I finally get it.

Just to recap.  I was using adapter classes, and at one point during a recent project re-org, I think I inadvertently moved them from server to shared package.  I moved only the adapter classes back into the server package.  Viola! - GWT-Compile is happy once again.


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/R7LbxAI9W_sJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Reply all
Reply to author
Forward
0 new messages