I would like to add some GWT (Google web toolkit) functionality to my existing web application built with maven (servlets, jsps etc). I have read some tutorials about GWT and managed to successfully write some basic examples but I can't seem to understand how to integrate it with my existing project. All the tutorials that I found focus on building this application from scratch (without Maven) or by crating new project with GWT archetype (with Maven).
How do I proceed with existing application (webapp archetype)? I tried adding the path do GWT SDK to the project and created basic HelloWorld class (I created separate package structire just for GWT) following THIS tutorial.
What I don't understand is how to setup everything correctly and where to place the configuration files? Is the config file supposed to be in the root folder of the project (next to pom.xml)? Should it be named the same as my project is named or based on the class specified as entry point?
Basically, my current structure looks like this:
This obviously does not work. Did I forgot some configuration? Are the locations wrong? Thanks for any help!
EDIT: I changed the structure of the project and added the maven dependencies. It seems that GWT is recognized now. However, it is still not running any GWT code when accessing the html page.
This is my silly test with CarRental.html (src/main/webapp/CarRental.html):
<html>
<head>
<title>CarRental</title>
<script language="javascript" src="carrental/carrental.nocache.js">
</script>
</head>
<body>
<h1>Hello World</h1>
<p>Welcome to first GWT application</p>
</body>
</html>
The CarRental.java (src/main/java/wa2.gwt.clients.CarRental.java):
package wa2.gwt.clients;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
public class CarRental implements EntryPoint {
public void onModuleLoad() {
Window.alert("Hello, World!");
}
}
Am I still missing something? I am accessing the html file by clicking it and executing run as > run on server (the webapp is deployed to my Tomcat server) or alternatively just typing the URL on localhost.
I have a Maven/GWT app with the following structure:
approot/pom.xml
approot/src/main/resources
approot/src/main/java/org/mydomain/MyApplication.gwt.xml
approot/src/main/java/org/mydomain/client/...
approot/src/main/java/org/mydomain/others/...
All the GWT Java code is in the client package, as deined in the gwt.xml file like this:
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.6.4//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.6.4/distro-source/core/src/gwt-module.dtd">
<module rename-to='resources'>
<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.resources.Resources" />
<inherits name="com.google.gwt.uibinder.UiBinder"/>
<inherits name="some.other.Dependency" />
<source path="client" />
<entry-point class='org.mydomain.client.Main'/>
</module>
Here, the source element specifies that all Java in the client package (and any sub-packages) is to be processed by the GWT compiler and converted into JavaScript. All other packages are server-side and are not converted. If you have no server-side Java, then you'll only have the client package.
You'll need the GWT dependencies. Here's the minimum, there are others:
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>
It is also important to include the GWT maven plugin, so the GWT compiler will run during a Maven build. Configure the plugin in your <plugins> section of your pom.xml. Here's an example:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With