How to debug a GWT application running on OSGi? - eclipse

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).

Related

How to configure gwt application on tomcat for debugging?

I am trying to debug a GWT application on Tomcat, but I don't know how to run/debug my application on Tomcat in Eclipse. I have so many links but I can't get a proper result.
I'm using -noserver -port 8080 and war file configuration but every time I get an error 404 while I run the application.
Here are some links that I follow but I can't configure:
http://groups.google.com/group/google-web-toolkit/browse_thread/thread/7511aca28b5f683c
https://developers.google.com/eclipse/docs/faq#gwt_in_eclipse_for_java_ee
http://jxpang.blogspot.in/2010/11/configure-external-tomcat-7-server-in.html
update
I am having same url but i think i am doing wrong configuration. is any body has proper solution for configure gwt web application with apche tomcat with debugging.
I want step by step configuration and running tutorial
please help me.
So you connect to the local server, but it can't resolve your URL?
If you stick with all the defaults, then in dev-mode you would use the following URL:
http://127.0.0.1:8888/index.html?gwt.codesvr=127.0.0.1:9997
But when configured on an external server you would need:
http://localhost:8080/MyApplication/index.html?gwt.codesvr=127.0.0.1:9997
Also make sure that in the 'Server' tab of your Debug configuration the option Run built in server is unchecked.
Hope this helps!
In Eclipse: right-click on your GWT project, and choose "Run As web Application (running on an external server)"
Then you can fill the field External root server (dns/ip and webapps folder for tomcat)

Tomcat REST services not deployed with Intellij IDEA

I have just switched to Intellij Idea (11) and I'm having possibly simple problem for which I cannot find a solution within Intellij IDE. I have a web application which contains some classes marked with annotations from javax.ws.rs like eg. #Path("/members") etc and my web.xml file configured for handling REST calls.
The application is build with Maven, when I package the application either from command line or through the Intellij IDE and copy the .war file into tomcat webapps directory manually, all works fine, eg. I can access GET based services from the browser.
If I deploy the application through configured tomcat in Intellij IDE the application works but without the REST portion, so I'm not able to execute any rest based calls (all end up with 404 error). I cannot see anything in logs about deploying rest service classes like I do during manual deployment:
INFO: Adding scanned resource: com.softberries.klerk.rest.MemberResourceRESTService
so its definitively an IDE configuration option I've missed which prevents tomcat from scanning classes for this annotations.
The question is how should I configure my Tomcat within the IDE to work the same as started manually.
with Intellij you need to expose the classes as web services from Tools > WebServices.
Also check that in Setting > Web Services, the prefix path for web service is correct (by default is /services).
Here you have a nice tutorial about how to create webservices in intellij.
http://www.academia.edu/4526516/Creating_Web_Services_Applications_with_IntelliJ_IDEA
By the way... when you do a deploy from intellij, the application goes to:
C:\Users\userName.IntelliJIdea10\system\tomcat\NameDeploy"
This info appears in the console as: "Using CATALINA_BASE": .../path...
Hope this helps,
Cheers

Debugging GWT server side code using a TomCat instance

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.

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.

GWT App through tomcat on Intellij-Idea 10

Sounds simple, but I'm having lots of issues.
I want to run a GWT project in a tomcat on Intellij-idea 10.
Does anyone know how to set up the run config?
Regards,
Charles.
You can use '-noserver' option to start Dev Mode under Tomcat. Edit your GWT run configuration by adding '-noserver -port 8080' to 'Dev Mode parameters' field, then run the Tomcat configuration and after that run the GWT configuration.
This all implies that this is a development run, i.e. for local testing/debugging purposes. This is not deployment to production servers. I also assume you have GWT and Web facets defined for this project.
If you need GWT debugging, then you must run as GWT run configuration: here you can only choose a Default server (Jetty that comes with GWT) or an AppEngine Development server (if installed).
If you must run under Tomcat, then:
a. Add a Tomcat server under Settings - App Servers.
b. Create an Artifact - WAR exploded (under project settings). Add all items in right pane to the left pane.
b. Create a Tomcat run configuration with this Artifact.
You first run gwt compiler for compile gwt module, then compiler creates to your hosted .js and .html files. And you can run tomcat as usual but tomcat does not compiles your gwt modules.
I suggest you t use ant to compile gwt modules.