vendredi 18 mars 2011

Starting with atmosphere framework, GWT and Maven under Eclipse

Months ago i was searching for a push solution to integrate to my web applications and I discovered Atmosphere, a nice framework, developed by nice people.

Latest version of Atmosphere is 0.8. Project is growing fast and development is intensive.

In this post, I want to summarize steps I followed to get atmosphere-gwt-demo working.

I use Eclipse Helios (3.6 SR2), I've already Maven plugin installed (m2eclipse), and google-eclipse-plugin (even if this one will not be used for the purpose of this article)

Download atmosphere project:

git clone https://github.com/jfarcand/atmosphere.git

Wait few minutes for download to complete then go to eclipse and import the entire project as a maven project.

Fix some maven properties:

Go to atmosphere-gwt-demo, we'll be editing the pom.xml. Locate the declaration of gwt-maven-plugin (see the complete configuration) and add
<copyWebapp>true</copyWebapp>

Without this line, maven will not copy files located under src/main/META-INF/ (Most important atmosphere.xml) and the application will not work.

For more information see: http://mojo.codehaus.org/gwt-maven-plugin/debug-mojo.html

Install dependencies:

Now, if you try to run the demo, you will get errors. This happens because you didn't install atmosphere runtime dependencies.

For each error (missing class), find its containing sub-project, right click on it -> run as ... -> maven install

Run the demo:

Right click on atmosphere-gwt-demo -> Run as -> Maven build ... and enter in the goal field: gwt:run

Wait few seconds for the embedded jetty server to start and load your application, then open the hosted mode url into your favorite browser (I use Google Chrome with the GWT plugin installed).

Debug atmosphere-gwt-demo

This post shows how to debug a GWT application with the gwt-maven-plugin.

I just changed the port from 8000 to 8001 because for some reason this port was already in use (I think eclipse uses it)

Add the following line to the gwt-maven-plugin configuration in pom.xml of atmosphere-gwt-demo

<debugPort>8001</debugPort>

Right click on atmosphere-gwt-demo->Run As->Maven build ...
In the following dialog, enter "gwt:debug" as goals, save it.

Click on the dropdown of the debug button on the toolbar, select "Debug Configurations".

In the left panel, find “Remote Java Application”, select it and click the icon for "New launch configuration" (top left corner). Accept defaults, save, and close.

Now, you are ready, start the debug server by running the debug launcher we just created. (the one with goal gwt:debug). When you see "Listening for transport dt_socket at address: 8001" in the console output, run the attach launcher we just created (the remote debugger).

Finally, here is the complete gwt-maven-plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt-version}</version>
<configuration>
<module>${gwtModule}</module>
<gwtVersion>${gwt-version}</gwtVersion>
<runTarget>http://localhost:8888/gwtDemo/gwtDemo.jsp</runTarget>
<noServer>false</noServer>
<sourcesOnPath>true</sourcesOnPath>
<debugPort>8001</debugPort>
<copyWebapp>true</copyWebapp>
</configuration>
<executions>
<execution>
<configuration>
<extraJvmArgs>-Xmx512m</extraJvmArgs>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>

5 commentaires:

  1. I am getting a 404 error when contacting http://localhost:8888/gwtDemo/gwtComet. any ideas?

    RépondreSupprimer
  2. May be you should try with:
    http://localhost:8888/gwtDemo/gwtDemo.jsp?gwt.codesvr=127.0.0.1:9997

    RépondreSupprimer
  3. Ce commentaire a été supprimé par l'auteur.

    RépondreSupprimer
  4. Thank you for the "copyWebapp" tip!

    RépondreSupprimer
  5. I've worked through your instructions and it all goes well. But, on running the demo in Chrome I get:

    onModuleLoad() threw an exception
    Exception while loading module org.atmosphere.samples.client.GWTDemo. See Development Mode for details.

    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
    at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:193)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Unknown Source)
    Caused by: com.google.gwt.dev.shell.HostedModeException: Something other than a boolean was returned from JSNI method '@org.atmosphere.gwt.client.impl.WebSocket::isSupported()': JS value of type JavaScript object(56), expected boolean
    at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:100)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeBoolean(ModuleSpace.java:186)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeBoolean(JavaScriptHost.java:35)
    at org.atmosphere.gwt.client.impl.WebSocket$.isSupported(WebSocket.java)
    at org.atmosphere.gwt.client.impl.WebSocketCometTransport.hasWebSocketSupport(WebSocketCometTransport.java:97)
    at org.atmosphere.gwt.client.AtmosphereClient$CometClientTransportWrapper.(AtmosphereClient.java:434)
    at org.atmosphere.gwt.client.AtmosphereClient.(AtmosphereClient.java:128)
    at org.atmosphere.gwt.client.AtmosphereClient.(AtmosphereClient.java:119)
    at org.atmosphere.samples.client.GWTDemo.initialize(GWTDemo.java:198)
    at org.atmosphere.samples.client.GWTDemo.onModuleLoad(GWTDemo.java:95)
    ... 9 more

    Any idea what might have gone wrong?

    Thanks,

    John

    RépondreSupprimer