开发者

Best Way to Build Library Code [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

Suppose I want to create some library code which could be shared across multiple GWT modules.

What is the typical method for reusing this library. Should I create a module for the library, and then import it inside my .g开发者_Go百科wt.xml file? Is there any way to release it as a jar?


Do it the way you would do any module. It doesn't have to be a web app, no additional configuration files are needed. Just sources packed up into jar file. The only real requirements are:

  1. Follow module creation guidelines:
    1. Prepare a *.gwt.xml descriptor file in root dir of your module.
    2. Have a client package for classes that are intented to be compiled to js and server for the rest.
  2. Be sure to include sources in jar file.

What is interesting, if your module does not depend on any GWT-specific classes or use jsni, you can use it with "normal" java applications as well.

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

And yes, once you have it in a jar, you can release it ;-)

The perfect example of such approach is Ext GWT (aka GXT): http://www.sencha.com/products/extgwt/ just download this library, unpack and see setup.txt for installation instructions and how is gxt.jar (a reusable module) done.


You need to create GWT modules:

See this tutorial: GWT Tutorial – Using and creating modules


I think the easiest way is to create a New Project (Web Application) and export it as JAR. In this way you have your library outside any other project.

When you export the library as a JAR, don't forget to include the source.

Then to add you library to another project you have to:

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

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

Another things that you can do in your lib is to include server side code, create a theme (including css, images, etc), etc.

This is very useful.

Hope this helps.


It appears there is now an Eclipse GWT Module Wizard by Google for just this task! http://code.google.com/webtoolkit/tools/gwtdesigner/wizards/gwt/module.html

Generally you create a module and then inherit it in your implementing module. You can implement this in various modules if you like.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜