Tuesday, September 4, 2007

Deploy GWT using external application server like JBoss

I wanted to use GWT with external application server. It is really easy to use GWT with embedded tomcat server. But, I needed advanced services provided by managed application servers like JBoss. After figuring out how to use GWT with external web servers, I am posting the details with an example web application.

Environment:
I am using GWT version 1.4.1. Instructions have changed from previous releases of GWT.

I expect the following system variables are set:

GWT_HOME
JAVA_HOME
JBOSS_HOME

Step 1: Create sample application using GWT scripts.

This will use embedded tomcat in step 1. Later on we will change it to use external web app server.

1) cd %GWT_HOME%

2) projectCreator.cmd -eclipse gwtjboss -out ..\gwtjboss

3) applicationCreator.cmd -eclipse gwtjboss -out ..\gwtjboss com.gwtjboss.client.GwtJbossTry

4) Now verify that the generated application is working with embedded tomcat using GwtJbossTry-shell.cmd
Note the URL in hosted browser http://localhost:8888/com.gwtjboss.GwtJbossTry/GwtJbossTry.html

5) Also try to bring up the hosted browser using GWT Eclipse launch configuration. It can be accessed from Run -> Debug... -> click GwtJbossTry under Java Application tree node.



Step 2: Change to use external application server

1) Run GwtJbossTry-compile.cmd script and copy the following files from 'www' output directory to %JBOSS_HOME%/server/default/deploy/gwtjboss.war

com.gwtjboss.GwtJbossTry\GwtJbossTry.html
com.gwtjboss.GwtJbossTry\history.html
com.gwtjboss.GwtJbossTry\com.gwtjboss.GwtJbossTry.nocache.js
com.gwtjboss.GwtJbossTry\hosted.html

2) Update GwtJbossTry-shell.cmd.
@java -cp "%~dp0\src;%~dp0\bin;%GWT_HOME%/gwt-user.jar;%GWT_HOME%/gwt-dev-windows.jar" com.google.gwt.dev.GWTShell -noserver -port 8080 -out %JBOSS_HOME%/server/default/deploy/gwtjboss.war %* gwtjboss/com.gwtjboss.GwtJbossTry/GwtJbossTry.html

We have made the following changes to *-shell.cmd:

  • Added -noserver to tell GWTShell not to start embedded tomcat.
  • Added -port 8080 because external server (JBoss here) is running on port 8080.
  • Changed output directory to D:\jboss\server\default\deploy\gwtjboss.war so that clicking compile button in hosted browser will automatically update the deployed application. Note that in complex application, we may need complex packaging mechanism to deploy application. So this compile feature may not be very helpful in complex application. [Not necessary]
  • Updated the path to HTML page.
To debug the client side code, we need to update the eclipse launch configuration too.
  • Go to Run -> Debug... -> click GwtJbossTry under Java Application tree node.
  • Update arguments.

3) Now set a breakpoint inside GwtJbossTry class and play around the page. If you hit the breakpoint, you are done.

This is all we need to do to use external server.
We we will hit the URL http://localhost:8080/gwtjboss/com.gwtjboss.GwtJbossTry/GwtJbossTry.html (assuming JBoss running on port 8080)from hosted browser, GWT's hosted browser will intercept Javascript calls and runs the corresponding Java code in its classpath.

Note the change in URL. We have added gwtjboss to URL. This is because of the fact that we have deployed the application gwtjboss.war

The directory listing of deployed application is:

D:\JBOSS\SERVER\DEFAULT\DEPLOY\GWTJBOSS.WAR
+---com.gwtjboss.GwtJbossTry

        com.gwtjboss.GwtJbossTry.nocache.js
        GwtJbossTry.html
        history.html
        hosted.html

The modified application is available at googlecode.
svn checkout https://gwt-external-server-jboss.googlecode.com/svn/tags/simple-gwt-jboss
simple-gwt-jboss
or simply download gwtjboss_v01.zip

In this simple example we haven't deployed any servlet and made call to that servlet from GWT client code. Doing that is also easy. We just need to copy compiled client + server code to WEB-INF\classes, gwt-servlet.jar to WEB-INF\lib and update web.xml. More on GWT with servlet deployed in JBoss (external server) later.

8 comments:

Anonymous said...

Very usefull turorial, thanks !

Anonymous said...

i wanted to know how 2 deploy server side code of gwt into jboss.Please mail the info if you have to shiva321@yahoo.com.

Thanks

Anonymous said...

Sure, it would be nice to present how to deploy also the server side code, without that it's potty.

vikasagrawal said...

this is really nice presentation
but i want to know how to deploy gwt application on jboss portal

Anonymous said...

Excellent article. Thanks!

Bhavesh said...

I am using gwt-windows-1.7.0 version.

While running the script I am getting warning that GWTCompiler has been deprecated and will be removed from the future version.

Can you provide proper steps for New Compiler?

One more thing I would like to know is where is the location of www directory? ("%~dp0\www" %*)

Bhavesh said...

I am getting following error message with your script...

Please help me out in resolving it.

C:\Documents and Settings\bhavesh.shah\My Documents\Downloads\gwtjboss_v01\gwtjb
oss>GwtJbossTry-compile.cmd
WARNING: 'com.google.gwt.dev.GWTCompiler' is deprecated and will be removed in a
future release.
Use 'com.google.gwt.dev.Compiler' instead.
(To disable this warning, pass -Dgwt.nowarn.legacy.tools as a JVM arg.)
Compiling module com.gwtjboss.GwtJbossTry
[ERROR] Unexpected
java.lang.OutOfMemoryError: Java heap space
at java.io.BufferedReader.(Unknown Source)
at java.io.BufferedReader.(Unknown Source)
at com.google.gwt.dev.javac.TypeOracleMediator.parseMetaDataTags(TypeOra
cleMediator.java:148)
at com.google.gwt.dev.javac.TypeOracleMediator.resolveTypeDeclaration(Ty
peOracleMediator.java:1451)
at com.google.gwt.dev.javac.TypeOracleMediator.addNewUnits(TypeOracleMed
iator.java:389)
at com.google.gwt.dev.javac.TypeOracleMediator.refresh(TypeOracleMediato
r.java:417)
at com.google.gwt.dev.javac.CompilationState.refresh(CompilationState.ja
va:179)
at com.google.gwt.dev.javac.CompilationState.(CompilationState.jav
a:93)
at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:2
64)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:283)
at com.google.gwt.dev.GWTCompiler.run(GWTCompiler.java:180)
at com.google.gwt.dev.GWTCompiler.run(GWTCompiler.java:150)
at com.google.gwt.dev.GWTCompiler$1.run(GWTCompiler.java:119)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)

at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(Compile
TaskRunner.java:82)
at com.google.gwt.dev.GWTCompiler.main(GWTCompiler.java:126)
[ERROR] Out of memory; to increase the amount of memory, use the -Xmx flag at
startup (java -Xmx128M ...)

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!