Debugging GWT server side code using a TomCat instance - gwt

I'm setting up a project to use MySQL as the datasource and I'm running into a couple problems.
It appears the MySQL drivers for the Java side are incompatible with the built in GWT Jetty instance. Really?
I can configure a TomCat instance and get MySQL Driver working, but I can't debug inline (Client & server together) like I normally would be able to do using the Jetty instance in dev mode, according to Google Docs.
I spent quite a while deciding between a PHP or Java backend, and one of the main advantages besides the GWT RPC mechanism was the fact that GWT provides a nice Development environment if you use Java.
Has anyone encountered the need to use a data source other than appEngine? How did you setup dev environment?

I do believe the MySQL JDBC driver is "compatible" with the embedded Jetty; but maybe you were in an AppEngine project, in which case the embedded Jetty server forbids the use of classes that are not compatible with AppEngine (so you have at dev time a behavior as similar as possible with the production environment on Google's servers).
To debug your server code running in Tomcat, you either need to launch it (the server code) using Eclipse WTP (or equivalent if you don't use Eclipse), or launch your Tomcat instance with the appropriate debug arguments e.g. -agentlib:jdwp=transport=dt_socket,address=8788,server=y,suspend=y, and then debug it as a "Remote Java Application" (in Eclipse, I don't now how they name it in other IDEs).
You can then launch your DevMode in -noserver mode (and in debug) to debug your server and client at the same time (yes, you'll actually have 2 debug sessions).
Note that the doc you refer to (whose latest version can be found here) doesn't deal with debugging the server-side code, as it's highly dependent on the server you use, how and where it's deployed, etc. GWT code on the server side is just a standard servlet, so there's nothing specific to GWT re. how to debug the server-side code.
FYI, we do use a standalone Jetty instance (not the embedded Jetty server) for more than a year using the above setup.

You can use GWT and Tomcat and still be able to debug both client and server side. Look at the jetty startup parameters in Eclipse.
I have been in a similar position few years ago and decided to use Jetty for development and tomcat for testing.

Related

How do I change instance when debugging Eclipse through Tomcat

I have a Java servlet application to maintain and have downloaded both the Live version and the Test version rom SVN to Eclipse (Helios) and have associated my Tomcat 7 with Eclipse to debug the applications. But when I attempt to Run or Debug the Test instance of the servlet on the associated Tomcat server Tomcat always seems to start the Live instance. For example when I attempt to start the Live Instance - in Eclipse it shows the URL to be;
https://localhost:8443/SWFinanceLive/WEB-INF/classes/path/to/web/request/entry/point.java
When I am expecting;
https://localhost:8443/SWFinanceTest/WEB-INF/classes/path/to/web/request/entry/point.java
How do I change the instance when running through the server in Eclipse?
This link seemed promising but then doesn't tell you how to change the setting;
tomcat server instance debugging in the eclipse
With the assistance of #Susie I was able to change the project root context. Things are working as I desire now

JBoss running on DCEVM - IDE claims that code replaced, but behavior doesn't change

I run JBoss on java7 DCEVM http://dcevm.github.io/
It's possible to Hot Swap any type of code changes from IntelliJ connecting to standalone Swing application (using remote debug; VM startup parameters -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=2222).
But when I try to do something similar when debugging application running on JBoss (connecting debugger remotely same VM parameters as previously) IntelliJ claims that hot code replace succeeded, however application doesn't change behavior as it should.
Do you have any ideas what could be the reason?
Is it connected somehow with the Java EE classloading model?
Has anyone experienced such problem?
Is it possible to hot swap code with DCEVM in JBoss using remote debug?
Try to use the following project: https://github.com/HotswapProjects/HotswapAgent. It uses DCEVM and solves hotswapping problems inside many java frameworks (Spring, JSF etc..)

Gwt and eclipse with jetty for production mode

Is there a standard easy way to launch Jetty from eclipse for the production mode?
I followed the instructions at http://code.google.com/webtoolkit/usingeclipse.html to setup a new project using gwt and eclipse.
The hosted (debug) mode seems to be already configured to work properly and involves one click in eclipse using "Debug as".
I would like to configure "Run as" to run the production mode in jetty. Is there a good tutorial on the standard way to set this up?
You have to compile your GWT-project before you can "Run As". It's the button with a red box and "G" on it.
Since GWT compiles to java script you don't need jetty if you don't have server-side logic... anyway, in a normal scenario you'll have some server interaction, BUT you're not sticked to jetty; tomcat or other server side technology could be used.
You can deploy the compiled JS to a web server and the server side logic to tomcat, jboss, jetty... even you could interact with php at the server.
Deployment to Google AppEngine is another option, a natural option if you use the eclipse plugin since it's tightly integrated with it.
In eclipse, Jetty is no more than a java process started like any normal java main.
Go to [Run]->[Run Configurations]->[Web Application]->[Your GWT Project] and you'll see a normal java main exec config.
Look at the [Main Class] option -> this is the embeded jetty ..or at
the [VM arguments] for the JVM
The ?gwt.codesvr= param in the URL only instruct the browser plugin to interact with the eclipse plugin embeded jetty in a way that only the modified code is re-compiled to JS and sent to the browser.
If you do not use the ?gwt.codesvr= probabilly you'll have to recompile all the project every time you change a single line of code.
I recommend you to clearly separate the compiled-to-js code and the server side code in different eclipse projects.
I also run the embeded jetty only for the client-side code; the server side code is run in tomcat.
That way I have a clear separation of layers at the time I can debug client-side GWT code and server-side java code.

How to debug a GWT application running on OSGi?

I'm developing a web UI using GWT. While working only with the widgets I could debug from Eclipse using the Firefox extension, but now that I'm integrating the UI with other OSGi bundles I cannot use this solution.
For deploying the GWT application I create the .war and convert it to an OSGi bundle using BND. Then I launch the OSGi container with all the bundles using Pax Runner and Pax Web and the application works correctly, but when something fails in the generated javascript code I don't have any decent output error or debugging facility.
Is there any way to launch the GWT application in "debug mode" from OSGi?
Any other idea that could help in this scenario?
Update: Could it be possible to instantiate com.google.gwt.dev.DevMode or its part with the browser connector from the Activator?
I've finally managed to launch development mode using OSGi, GWT and optionally eclipse. The solution was on the -noserver flag of the GWT dev mode, it's not aware of the changes in code while the application is running, but it can be used for debugging the compiled code and to receive the exception traces.
I also managed to run the development shell without eclipse, but if you are not interested on this solution you can directly jump to the eclipse integration section.
Without Eclipse (only exceptions, no debug)
You need to know the following information:
Where do you have your source ($SRC)
Where do you have your GWT libraries ($GWT_PATH), specially gwt-user.jar and gwt-dev.jar.
(Optionally) the port from wich your HTTP OSGi server serves the application ($PORT).
The startUp url of your application ($URL)
The package containing the .gwt.xml file for your application ($PACKAGE).
Then you need to run:
java -cp $SRC:$GWT_PATH/gwt-user.jar:$GWT_PATH/gwt-dev.jar \
com.google.gwt.dev.DevMode -noserver -port $PORT \
-startupUrl $URL $PACKAGE
E.g.:
java -cp src/:lib/gwt-2.0.3/gwt-user.jar:lib/gwt-2.0.3/gwt-dev.jar \
com.google.gwt.dev.DevMode -noserver -port 8080 \
-startupUrl httplocalgui.html es.warp.samples.httplocalgui
And finally you only need to deploy your application as usual, in my example I do it with pax-runner and pax-web, using the default port 8080.
With Eclipse
Open the debug configuration for your project
Go to Server tab and uncheck "Run built-in server"
Go to Attributes tab and add "-port 8080" (if 8080 is the port used by your web container). I think that this argument without the built-in server is only used to create the url that the development mode generates to invoke the browser (or that elipse uses to generate an url you can copy and paste in your browser's address bar).
Deploy your application.
Access it from a browser with the GWT extension installed (and don't forget to add ?gwt.codesvr=127.0.0.1:9997)
I had the same problem lately and unfortunately I haven't found any good solution.
Eventually I created mock implementations of all GWT services I am using in my client side code. When I need to debug client side code I am just switching to these services instead of real services using OSGi underneath. Then in Eclipse I can run GWT application in debug mode. This is far from perfect and requires some work with mocks but it works for me (at least now).

How do you setup JNDI for GWT (2.0) Hosted Mode?

How do you setup a JNDI server on GWT's hosted mode (they seem to use an embedded Jetty server)?
You can switch to any external Java server and use it without problems with GWT (I'm assuming here that you already have a working configuration and you don't want to migrate it to GWT's embedded Jetty, which may or may not prove to be difficult). For more details see the good docs.