Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to properly bundle GWT with my webapp? (was: why gwt-user-1.7.0 contains Servlet API classes)

Tags:

gwt

Does anyone know any sane reason for such bundling decision? Google engineers act wisely in most cases, so this kinda surprized me.

This would cause collisions with other versions of servlet API pulled via Maven dependencies:

  • webapp classpath will likely contain version which is bundled with GWT;
  • container may refuse to load the GWT jar as it contains the javax.servlet package;
  • in most cases this will likely deviate classpaths across your IDE's debugger and the really executing VM.

Link to the jar in question (just so you see the same thing after unzipping as I do, if you don't believe that GWT contains servlet API classes in the same jar): http://repo1.maven.org/maven2/com/google/gwt/gwt-user/1.7.0/gwt-user-1.7.0.jar

like image 450
Anton Kraievyi Avatar asked Jan 15 '11 16:01

Anton Kraievyi


2 Answers

You shouldn't be including gwt-dev.jar or gwt-user.jar in your war file. You only need gwt-servlet.jar in your war, and that too only if you are using RPC. If you notice, gwt-servlet.jar (ironically) does not contain any of the servlet classes.

  • gwt-dev.jar contains the compilers and linkers. Your code will never need this to compile.
  • gwt-user.jar contains the gwt framework that ultimately gets translated to javascript. You only need this during development mode.
  • gwt-servlet.jar contains the server side code that is needed if you use RPC framework. This is the only jar that should be present in your war file.
like image 157
Sripathi Krishnan Avatar answered Sep 27 '22 20:09

Sripathi Krishnan


The reason the classes are in the package is to provide a full working solution for users who only use the gwt-user file in development. Without it GWT RPC wouldn't compile. This is/was the general view of the GWT team as can be found in this lively discussion on the GWT issue tracker: http://code.google.com/p/google-web-toolkit/issues/detail?id=3851

However, GWT 1.7 also contains the javax source files, which can cause additional problems. For example for maven and probably also for the points you mention. This was addressed in the GWT issue and in later version of GWT the javax source files have been removed from the gwt-user jar file.

For deployment you should use the gwt-servlet jar, which doesn't contain the javax classes or any other third party libraries. In the past several it could happen GWT files designed for client side use also used on the server side were missing from the gwt-servlet jar file. Losts of these issues have been addressed and classes were added to the servlet jar file. If you still find a GWT class you need is missing from the gwt-servlet you should file an issue report. In your case, assuming you're using 1.7, it might mean to upgrade to a newer version of GWT.

like image 23
Hilbrand Bouwkamp Avatar answered Sep 27 '22 21:09

Hilbrand Bouwkamp