Best Way to Build Library Code [closed]
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:
- Follow module creation guidelines:
- Prepare a
*.gwt.xml
descriptor file in root dir of your module. - Have a
client
package for classes that are intented to be compiled to js andserver
for the rest.
- Prepare a
- 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:
- Add the JAR to the build path.
- 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.
精彩评论