Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include a external jar in a GWT (Google Web Toolkit) project?

Tags:

java

jar

gwt

I have a external jar file named "xxx.jar". I use "xxx.jar" in my GWT project.

When I attempt to build the JavaScript version of my project in Ant, I get one of the following type of errors at every location in which I use xxx. I get a error of this kind when doing the "gwtc" task in Ant, the javac compilation process proceeds just fine.

[ERROR] Line 45: No source code is available for type org.xxx.ObjectName; did you forget to inherit a required module?

Ok, so clearly it is not able to see/use the xxx.jar. Fixing this problem however is not as simple in GWT as it is in "plain" java. From the internet ref1, I gather that I need to

  1. Include all the source (.java) files from xxx.jar in a source directory
  2. Add this source directory in some sort of new gwt.xml file
  3. Hope and pray that all the java files are translatable by GWT :/

So... What exactly do I do? what is this gwt.xml file I need to generate (Step 2)? Where do I put the source directory, and how to I reference it (Step 1)? What exactly are the mechanical steps necessary to add a external jar file in GWT?

like image 949
Stephen Cagle Avatar asked Jul 14 '10 03:07

Stephen Cagle


1 Answers

Because your GWT source has to be compiled to JavaScript to work on the client side browser it makes sense that the source code should be available to the GWT compiler.

Check out Lars Vogels article with a brief section on this in his tutorial

It also makes sense, due to the restrictions that Google Outline that all of the code in this JAR may not compile to GWT javascript even if you can get the source.

GWT supports only a small subset of the classes available in the Java 2 Standard and Enterprise Edition libraries, as these libraries are quite large and rely on functionality that is unavailable within web browsers. To find out exactly which classes and methods are supported for core Java runtime packages, see the GWT JRE Emulation Reference

Robert Hanson provides a step by step on how to package GWT components

Good Luck...

like image 180
MadMurf Avatar answered Sep 24 '22 13:09

MadMurf