How do package a widget in a jar file?

386 views
Skip to first unread message

IamRobe...@gmail.com

unread,
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?

IamRobe...@gmail.com

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

Christian Wolf

unread,
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.

dab...@gmail.com

unread,
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

unread,
May 23, 2006, 2:07:07 PM5/23/06
to Google-We...@googlegroups.com
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:
 META-INF/
 META-INF/MANIFEST.MF
 org/
 org/hanson/
 org/hanson/gwt/
 org/hanson/gwt/client/
 org/hanson/gwt/client/Heading.class
 org/hanson/gwt/client/Heading.java
 org/hanson/gwt/Components.gwt.xml

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)
some.package.xyz.* (anything else)


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

package org.hanson.gwt.client;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Widget;

public class Heading extends Widget
{
    public Heading ()
    {
        setElement(DOM.createElement("h1"));
        setStyleName("rhw-heading");
    }
   
    public void setText (String s)
    {
        DOM.setInnerText(getElement(), s);
    }
}


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

<module>
    <inherits name='com.google.gwt.user.User'/>
</module>

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 http://makeashorterlink.com/?G4332572D)


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.

Example:
<module>
    <!-- Inherit the core Web Toolkit stuff -->
    <inherits name='com.google.gwt.user.User'/>

    <!-- ** 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/>
</module>

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 com.google.gwt.user.User.  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.

dab...@gmail.com

unread,
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
source.

Steve Storey

unread,
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:

gwt/org/something/Component1.gwt.xml
gwt/org/something/public/myResource1.gif

in Component1.jar and

gwt/org/something/Component2.gwt.xml
gwt/org/something/public/myOtherResource.gif

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.

Steve

aglaforge

unread,
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.

aglaforge

unread,
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
Forward
0 new messages