Friday 14 June 2013

GWT + Maven + Eclipse - alternative project setup

Mission

Create alternative GWT project template ideal for multiple small applications, multiple EntryPoints, a playground project setup, where one click on EntryPoint class will launch browser will run that EntryPoint and only that EntryPoint.

Project sources

Goals

  • Developers friendly setup
  • Provide project template for test, playground and technical spike style projects.
  • Perfect for ultra short modify-execute development cycles. Change is reflected immediately and browser opens with the right content.
  • Focus only on Client Side code (Java to JS) - create environment perfect for simple testing of things like positioning, events, DOM manipulation, visual stuff,..
  • Maven only based setup. Rely only on Maven provided libraries. No GWT and Web project plugin dependencies. Preven library duplication often introduced when using combined Maven and GWT plugin.
  • Rely only on Code Server on-the-fly compilation from Java to JS. It is light fast this way! Changes to Java sources are reflected immediately. Avoid slow full Java to JS compilation, either by Maven or Eclipse GWT plugin, in build time.
  • Avoid need of Eclipse launchers. With currently necessary to add client source directories to classpath)
  • start GWT app as easily as possible and as quickly as possible.
  • support large number of GWT apps easily in one project. Support one application == one class == one click to run. Ideal for testing or demonstrating specific topics in isolation. Vanilla GWT setup is not very helpful in that.
  • Have more control on app start process. Be able to influence any part of the process, be able to debug Code Server or Http Server. Expose what is under the hood of individual components.
  • This setup is not intended for production code. Default setup created by Maven GWT plugin or Eclipse GWT is perfect for production indented project, stick with it.
  • No need to touch GWT module descriptor when adding new EntryPoint.

How to run it

  • Clone project from my Git repository.
  • Run usual mvn clean install.
    • Do it from command line or, if you have Eclipse Maven plugin e2m installed, there is a menu for it.
    • Ideally, you would need to run Maven build just once, on the beginning, to set up everything.
  • Write your entry EntryPoint class
    • It can be an entry to a bigger application or a mini application in one class
    • Write as many EntryPoints as you wish
    • Class must be placed in the client code package (currently my.code.client)
    • Check provided Sample1.java.
  • Write app runner class, a class with main method, and one line of code
    • Its a class with main() method making it directly runnable class in all IDE, not only Eclipse. It that main() method is one call; it will check if servers are running and opens browser on the right URL for you
    • It is not required, it is a recommended convenience
    • See Sample1Run.java. More or less a copy and paste.
  • Run HttpServer (RunHttpServe.java)
  • Run GWT CodeRerver (RunCodeServer.java)
    • If you forget to run any of the required servers you will be kindly reminded, detection mechanism is in place. Keep this server running between individual your EntryPoint application runs.
  • Run your application
    • your EntryPoint, ideally with the prepared runner. Runner conveniently opens browser for you on the right URL, like this one http://localhost:8080/my.code.client.Sample3.do?gwt.codesvr=localhost:9998
    • Your Entry Point class is immediately executed and you are presented with results in a new browser tab or window.
    • Edit your code, re-run your launcher, it should immediately reflect your changes.
    • Recompilation is fully transparent, courtesy of running Code Server, it is incremental, and is fast.
    • Edit, rerun, again, and again, and again..
    • And new EntryPoint. There is no need to touch GWT module descriptor (*.gwt.xml).

How to run it - alternative

  • Creating a runner class for your Entry Point class is not essential but convenient. You can run you app by entering URL directly, the format is:
    http://localhost:8080/[qualified entry class point class name].do?gwt.codesvr=localhost:9998 

Screenshot of the template in action. Note, no GWT plugin is installed, just plain Eclipse and Maven Eclipse plugin (M2E), all relevant directories are unfolded:
For comparison an original setup, note several apparent issues, like multiple version of GWT libraries and necessity to use launcher to add sources to classpath (highlighted items):
 

TODOs and leftovers

  • I am working on a YouTube show case video
  • I am considering to make the whole web app a project resource. That is everything there, html files, css files, etc, will end up on classpath.
    Benefits: any change to CSS would be immediately reflected in application; no need to call Maven. New servlet would be needed - ExposeResourceDirectoryServlet (based on ExposeDirectoryServlet)
  • Check Maven resource definition, perhaps too restrictive excludes/includes.
  • gwt-dev should not be in the classpath. It contains potentially conflicting classes, like Apache IOUtils. The whole library is mess! But where else I can get Code Server classes! (DevMode, ..)
  • Adding tools.jar is not without troubles. This library is not in any Maven repository, it is part of JDK installation. The only way how to make it Maven dependency is to use SystemPath dependency type, otherwise strongly discouraged. There are known issues with OSX systems having non-standard location and name of tools.jar, and openJDK allegedly have tools.jar already in the classpath. Classes from tools.jar are used to monitor if required servers are running.
  • Much of the set up infrastructure has not been widely tested. It is just on "works for me" basis. It has been tested on Windows and Linux, but not on OS X.
  • Code Server prints annoying useless (?) exception when browser is closed com.google.gwt.dev.shell.BrowserChannel$RemoteDeathError: Remote connection lost.
    I don’t know how to suppress this, but is is harmless.

No comments:

Post a Comment