问题
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
- Java source is compiled into Java byte-code .class files.
- Compiled .class files during development as well as during deployment.
- compiled .class files can be used in the classpath of both development and deployment
- 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.
- 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.
- GWT is client side development.
- GWT is compiled into Javascript.
- The resulting javascript are packaged into a war folder.
- i.e., GWT compiled into executable files are javascript files.
- GWT compilation requires all Java classes to be source files.
- Any Java library referenced by your Java classes must also be Java source files.
GWT war
- GWT also facilitates client side alignment and communication with server side.
- The server side is normally traditional Java deployed into JEE war structure.
- Therefore a deployment war has both GWT client compiled into javascript as well as JEE .class bytecode files.
- However, the GWT javascript files are placed in the URL-visible part of the war, together with HTML, CSS and other URL-addressable resources.
- Server side compiled java bytecode files or jars are placed into the class and lib directories which are not URL-addressable.
Therefore,
- GWT compiled deployment structures cannot be used for development.
- GWT is compiled into javascript deployment war structure.
- There is "no such thing" as packaging GWT compiled resources into a jar for deployment.
- Compiled GWT resources must be packaged into the URL-addressable side of the war.
- 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