• Home
  • RSS Feed
  • Log in


Using Google Web Toolkit with Eclipse WTP
Posted by Marco Mulder in the late afternoon: August 17th, 2006

I am writing a GWT application and want to test this application both in the GWT shell and in Tomcat. The application uses different Eclipse projects for the GWT UI and for the business service layer.

I found out that this can easily be done if you use an Eclipse WTP dynamic web project instead of the standard Java project that is created by the GWT projectCreator.

Using a dynamic web project has the following advantages:

  • It is possible to use external jars and other Eclipse projects from services that are implemented with the RemoteServiceServlet.
  • It is easy to test the ‘compiled’ JavaScript version in tomcat without having to create and deploy a war file.
  • It is easy to export a war file that can be deployed in any application server.

There is an Eclipse plugin for using GWT with WTP: Googlipse . However, this plugin does not (yet) support launching the ‘compiled’ JavaScript application. I will outline the steps that allow you to launch the JavaScript version of a GWT application in WTP.

How to create a GWT application in a dynamic web project

The recipe to create a GWT application in a dynamic web project is as follows:

  • Create a dynamic Web project MyProject in Eclipse WTP
  • Use GWT projectCreator without overwriting the .project and .classpath files:projectCreator.cmd -ignore -eclipse MyProject
  • Use GWT applicationCreator to create a GWT application:applicationCreator.cmd -eclipse MyProject com.mycompany.client.MyApplication
  • Add gwt-user.jar and junit.jar to the .classpath file:
    <classpathentry kind="lib" path="C:/gwt-windows-1.1.0/gwt-user.jar"/>
    <classpathentry kind="var" path="JUNIT_HOME/junit.jar"/>
  • Search and replace “www” to “WebContent” in MyApplication.launch, MyApplication-compile.cmd and MyApplication-shell.cmd
  • Copy gwt-servlet.jar to WebContent/WEB-INF/lib

Testing the application

You can use the generated launch configuration to test the application from the GWT shell. The WTP tooling ensures that libraries that are used by the web project will be on the classpath.

To test the ‘compiled’ JavaScript application:

  • Compile Java source into JavaScript using MyApplication-compile.cmd
  • Select “Run as –> Run on Server” from the context menu of MyProject
  • Open a browser on the URL of the application:
    http://localhost:8080/MyProject/com.mycompany.MyApplication/MyApplication.html

Implementing and invoking a service

To invoke a service in a way that works both in the GWT shell and in the ‘compiled’ JavaScript application, you have to use GWT.getModuleBaseURL() when setting the endpoint.

For example, if you implement a service “myservice” in package com.mycompany.server.MyServiceImpl:

  • Use GWT.getModuleBaseURL() in the serviceEntryPoint:endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "myservice");
  • Specify the full path in MyApplication.gwt.xml:
    <servlet path=">/com.mycompany.MyApplication/myservice" class="com.mycompany.server.MyServiceImpl"/>
  • Specify the path also in WebContent/WEB-INF/web.xml:
<servlet>
    <servlet-name>MyService</servlet-name>
    <servlet-class>com.mycompany.server.MyServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>MyService</servlet-name>
    <url-pattern>/com.mycompany.MyApplication/myservice</url-pattern>
</servlet-mapping>
Share

Filed under Java | 3 Comments »



3 Responses to “Using Google Web Toolkit with Eclipse WTP”



    Silvester Van der Bijl Says:
    Posted at: August 21, 2006 at 10:14 pm

    There is a modified version of Googlipse. See: http://wagenknecht.org/blog/archives/2006/08/yet-another-gwt-plug-in.html

    Reply


    Edoardo Says:
    Posted at: September 14, 2006 at 12:44 pm

    Even if there are toolkits for doing this job, this is a very good explanation

    thanks

    Reply


    Giancarlo Says:
    Posted at: December 3, 2010 at 3:04 pm

    can you post the source code of this project?

    Reply


Leave a Reply

Click here to cancel reply.


Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India
  • Xebia Sweden

Categories

  • Java (311)
  • Agile (181)
  • General (136)
  • Scrum (67)
  • Architecture (64)
  • Testing (59)
  • Performance (46)
  • Middleware (56)
    • Deployment (38)
  • Xebia Labs (39)
  • SOA (31)
  • Podcast (31)
  • Project Management (28)
  • Tools (26)
  • Uncategorized (20)
  • lean architecture (20)
  • Quality Assurance (17)
  • Articles (13)
  • Requirements Management (13)
  • Virtualization (19)

Tag Cloud

    Agile product owner lean architecture Groovy JPA implementation patterns agile architectuur Hibernate Architecture Scala Xebia Maven Moving to India Eclipse Frameworks Javascript XML Oracle Java lean architectuur Concurrency Control Flex JPA SOA Grails Scrum TDD ACT Lean Ajax Spring

Archives

  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
Avatars by Sterling Adventures