4

The GWT documentation states that all the source code for compilation to JavaScript on the client-side must be in a subpackage of the gwt.xml file. How does this work for when one references third party libraries?

Specifically, if I have a library foo.jar and I want to use some POJOs (which are Serializable) and do not suck in any non-Serializable code, how can I use these POJOs? How do I tell GWT where the source code is for them?

1
  • I found a solution, I'm not sure if it's the blessed way, but I've placed the full write-up in my blog: gordonizer.com/2012/01/… Commented Jan 17, 2012 at 16:37

2 Answers 2

5

Remember too that the GWT compiler needs actual Java source to compile to javascript, so it isn't enough that the classes are available and that all are serializable. For RPC to send the classes over the wire, they must be able to be used as JS when they get to the client.

That said, take a look in gwt-user, at the module javax/validation/Validation.gwt.xml. This file is put there so that other packages in javax.validation - even in other jars - can be compiled into JS for client-side validation. if you have a jar (and sources) on your classpath with code in com.thirdparty.pojos, you can create a module file in your own project in that same dir in your own source (something like com/thirdparty/pojos/ThirdParthRpc.gwt.xml, and put a <source path="" /> element in it to indicate that the entire package is legal for translation to JS. There will likely be some files that cannot be translated - use the exclude tag to deal with those.

Sign up to request clarification or add additional context in comments.

1 Comment

Right. I put the full write up below. It was failing with a REALLY weird ClassCastException, but then I saw your comment about the excludes a light went off and sure enough, I had other classes in that package that I didn't want serialized (and hadn't fixed to make them OK for GWT). So, thanks for that!
0

If you have control over packaging foo into foo.jar, and you have all the sources, then it's easy.

If you have a packaged foo.jar, and happen to have the source code, then you need to expand the foo.jar, copy the source into the exploded .jar directory, generate a simple GWT module.xml file and add an tag to your project’s module.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.