Best way to create library code

Suppose I want to create some library code that could be used for several GWT modules.

What is a typical reuse method for this library. Should I create a module for the library and then import it into the .gwt.xml file? Is there any way to free it like a jar?

+8
gwt
source share
4 answers

Do it the way you would any module. This should not be a web application, no additional configuration files are required. Just the sources are packaged in a jar file. Real requirements:

  • Follow the instructions to create the module:
    • Prepare the descriptor file *.gwt.xml in the root directory of your module.
    • You have a client package for classes that are meant to be compiled into js and server for the rest.
  • Be sure to include sources in the jar file.

Interestingly, if your module does not depend on any GWT classes or uses jsni, you can use it also with "normal" Java applications.

The answer to the second question (how to reuse it) is simple: add the newly created jar to your classpath and inherit this module in the module descriptor of your web application.

And yes, if you have it in the bank, you can let it go, -)

A great example of this approach is Ext GWT (aka GXT): http://www.sencha.com/products/extgwt/ just download this library, unzip and see setup.txt for installation instructions and how to execute gxt.jar (reused module).

+5
source share

You need to create the GWT modules:

See this tutorial: GWT Tutorial - Using and Creating Modules

+5
source share

I think the easiest way is to create a new project (web application) and export it as a JAR. So you have a library outside of any other project.

When you export a library to a JAR, be sure to include the source.

Then, to add your library to another project, you need to:

  • Add the JAR to the build path.
  • Include the dependency on your library in the module descriptor (com.mycompany.myproject.Myproject.gwt.xml)

<inherits name='com.mylibrary.mylib.Mylib'/>

Other things you can do in your lib is to include code on the server side, create themes (including css, images, etc.), etc.

It is very useful.

Hope this helps.

0
source share

It looks like Google now has an Eclipse GWT Module wizard for this task! http://code.google.com/webtoolkit/tools/gwtdesigner/wizards/gwt/module.html

Typically, you create a module, and then inherit it in your deploying module. You can implement this in various modules if you wish.

0
source share

All Articles