How do package a widget in a jar file?

Skip to first unread message

May 22, 2006, 11:40:48 PM5/22/06
to Google Web Toolkit
I am trying to package up some widgets for reuse, but when they live in
a referenced jar file it seems they can't be seen/used.

I have the proper gwt.xml file in the jar, which is referenced from my
project (inherited), and I also bundled the Java source for the widget
in the jar as well. Still no luck, and the error messages aren't
overly helpful.

Has anyone had any luck with this?

May 23, 2006, 8:46:56 AM5/23/06
to Google Web Toolkit
Nevermind, I figured it out.

Christian Wolf

May 23, 2006, 1:26:45 PM5/23/06
to Google Web Toolkit
Would you mind sharing your solution? Or is this a trivial task?

I didn't bump into this, but I might in the future.

May 23, 2006, 1:35:41 PM5/23/06
to Google Web Toolkit
Yes - please post your solution - I'm having the same problem.

Robert Hanson

May 23, 2006, 2:07:07 PM5/23/06
I created a widget called "Heading" which wraps the text in the appropriate <h1></h1> HTML tag.

The contents of the JAR file look like this:

The widget class AND source must be in the "client" package (you can change this in the gwt.xml file if needed).  The source must be present for the compiler to generate the JavaScript.

The structure of the JAR, in general, should be like this:

some.package.MyName.gwt.xml (project properties)
some.package.client.* (code to be compiled to JavaScript)
some.package.public.* (images or other files)* (anything else)

==== The source for the Heading widget ====

package org.hanson.gwt.client;


public class Heading extends Widget
    public Heading ()
    public void setText (String s)
        DOM.setInnerText(getElement(), s);

==== contents of Components.gwt.xml ====

    <inherits name=''/>

NOTE: If you have your client code somewhere other than the "client" Java package, you need to speficify that here.  Same goes for the "public" package.  (See

To use this JAR in your project you need to make a few changes:

1. Alter your *gwt.xml project file to reference the project file in the JAR.

    <!-- Inherit the core Web Toolkit stuff -->
    <inherits name=''/>

    <!-- ** ADD THIS ** Inherit the stuff from the jar ** ADD THIS ** -->
    <inherits name='org.hanson.gwt.Components'/>

    <!-- Specify the app entry point class. -->
    <entry-point class='org.hanson.gwt.client.MyApplication/>

2. Edit the MyApplication-shell.cmd and MyApplication-compile.cmd scripts, add the jar to the classpath.

That should be it.

You should take a look at the gwt-user jar.  You will find several project files in there, including  You will see that this file references other projects, some of which use some currently undocumented tags.  Note that for each project in the gwt-user.jar file there is a "client" package, and optionally a "local" package.  You will see that the images for the Tree widget are in one of the "local" packages.

Anyway, let me know if that helps.

May 23, 2006, 2:43:00 PM5/23/06
to Google Web Toolkit
Thank you Robert - that helps. The crucial step was including the java

Steve Storey

Jun 19, 2006, 2:42:48 PM6/19/06
to Google Web Toolkit
Something else I've discovered on this topic - the compiler won't pick
up the "public" directory for a single package from 2 different JARs -
this becomes an issue if you have say:


in Component1.jar and


in Component2.jar - in this case, only one component's public directory
content will be included by the compiler (although it will compile
everything else fine). You need to ensure that all the components are
in different namespaces when in different JAR files.



Jun 19, 2006, 3:47:17 PM6/19/06
to Google Web Toolkit
Figured a problem related to the default project google GWT creates,
which causes an Eclipse configuration issue. The Project.launch file
has the "default classpath" disabled so it doesn't pull in the
approrpriate libraries for the project classpath.

The solution is to go into the Run menu, select the Run profile for
your project, click on Classpath, and add the GWT libraries to your
User Entries.


Jun 19, 2006, 3:50:29 PM6/19/06
to Google Web Toolkit
Apologies, a better solution would be to add your project to the
Classpath, using the method described in the previous note.

Reply all
Reply to author
0 new messages