Need Help Packaging a GWT Library Module into a JAR

天大地大妈咪最大 提交于 2019-12-07 19:44:13

问题


I am trying to package a GWT library module into a JAR file and use the library in a separate GWT web app by adding the JAR file into its class path.

The JAR contains:

  • Java sources
  • RequestFactory generated sources
  • UiBinder generated sources
  • class files
  • library module descriptor
  • UiBinder XML files

The library module is inherited from the web app:

<module> <!-- my web app's module descriptor -->
    ...
    <inherits name="[path to my library module].Library"/>
    ...
</module>

However, I am running into

Deferred binding failed for '[path to mylibrary].client.ClientFactory'...

error when I try to launch the web app, which initializes the library in its onModuleLoad() method. The failure is caused by UiBinder views and RequestFactory that the library module uses. Launching in development mode or compiling the web app results in errors with messages stating missing CSS files and illegal references to generated source under emul.java.util package (I tried including this package and all other generated source in the JAR, but it didn't help.)

Can someone tell me what needs to be included in the JAR? Are there any additional resources required for library modules that use UiBinder and RequestFactory?

Has anyone successfully packaged a GWT library module that uses RequestFactory and UiBinder into a JAR?

Further clarification: The question is about creating a GWT library module; a module that includes client and server components, RequestFactory and UiBinder. Note that a GWT library module is packaged into a JAR whereas a regular GWT module with an entry point is packaged into a WAR. My attempts to package such a library module and GWT <inherit> from another GWT project have failed.


回答1:


Either, I misunderstand your question, or you mis-correlated GWT compilation with Java byte-code compilation.

Traditional Java development

  1. Java source is compiled into Java byte-code .class files.
  2. Compiled .class files during development as well as during deployment.
  3. compiled .class files can be used in the classpath of both development and deployment
  4. It does not matter if the .class files are jars or in folder hierarchy as long as their location is compliant to their respective package namespace.
  5. Java source files cannot be deployed into the deployment class path, but you can deploy JSP source files into the war as JSPs.

Not so for GWT.

  1. GWT is client side development.
  2. GWT is compiled into Javascript.
  3. The resulting javascript are packaged into a war folder.
  4. i.e., GWT compiled into executable files are javascript files.
  5. GWT compilation requires all Java classes to be source files.
  6. Any Java library referenced by your Java classes must also be Java source files.

GWT war

  1. GWT also facilitates client side alignment and communication with server side.
  2. The server side is normally traditional Java deployed into JEE war structure.
  3. Therefore a deployment war has both GWT client compiled into javascript as well as JEE .class bytecode files.
  4. However, the GWT javascript files are placed in the URL-visible part of the war, together with HTML, CSS and other URL-addressable resources.
  5. Server side compiled java bytecode files or jars are placed into the class and lib directories which are not URL-addressable.

Therefore,

  1. GWT compiled deployment structures cannot be used for development.
  2. GWT is compiled into javascript deployment war structure.
  3. There is "no such thing" as packaging GWT compiled resources into a jar for deployment.
  4. Compiled GWT resources must be packaged into the URL-addressable side of the war.
  5. There is "no such thing" as classpath in the compiled javascript files. Any classpath concept within javascript is simulated for JSNI's convenience.

In Conclusion

Compiled GWT resources are unusable nor will they be visible for GWT development because ... GWT development requires java source, and GWT client deployment are javascript in war, and javascript is not like bytecode jars/files.

Therefore, in GWT, there is "no such thing" as packaging a jar that is usable for both development and for deployment. Some examples and tutorials do package development and deployment files into a single jar - but that jar is essentially a zip which you have to break up the deployment pieces from the development pieces first.

GWT Development jars = source jars,

GWT Deployment = war of javascript and resources.

Before you launch yourself into GWT development, you should have at least 3-6 months' experience writing traditional JEE apps with JSP, servlets, HTML and javascript. That would help you inculcate a strong sense of segregation of server-side vs client-side, war vs jar and hence understand why GWT was invented in the first place. You would understand the deployment process.



来源:https://stackoverflow.com/questions/8623764/need-help-packaging-a-gwt-library-module-into-a-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!