Showing posts with label tomcat. Show all posts
Showing posts with label tomcat. Show all posts

Thursday, November 15, 2012

Debugging GWT using eclipse and tomcat

Everything I've heard and read online indicated that setting up my eclipse to debug the client side portions of a GWT app is super easy ... so of course I end up flailing around helplessly into the wee hours trying to debug a supposedly simple client side bug.  My process up to this point has been to insert a crazy amount of ridiculous log statements into the code, compile, deploy, repeat.  I know that this is messy and sloppy, but I was adamantly against using the GWT debugger because of a prior attempt to get it going a year and half ago that turned into a huge time-suck and frustrations.  After having spent an exceedingly long night trying to debug something a few months ago that ended up taking as long as it did because of the multiple repetitions of inserting log statements, compile, deploy, repeat, I conceded that I had to get the GWT debugger working.

First off, I am deploying the application in a local tomcat, so I need to be able to debug what eclipse considers an external server ( as opposed to having eclipse / gwt spin up a server within eclipse ).  A quick google search for the keywords of interest brings up as the first result a very helpful stackoverflow answer:


  1. Get google plugin for eclipse
  2. The in eclipse, right click on your project and choose Debug as -> Web Application (running on external server)
  3. Enter URL of your web app on tomcat (like http://localhost:8080/YourApp/YourApp.html and eclipse will give you new one - it will add stuff like ?gwt.codesvr=127.0.0.1:9997

Simple, right?  Sadly step 2 did nothing for me.  I select it, and nothing happens.  So what I ended up doing was to set up my own debug configurations.  When I did this, I kept getting this annoying error:


Working directory does not exist: /Users/myStuff/Documents/workspace/myProject-TRUNK/webapp/helloWorld/target/helloWorld-webapp-1.7-MS2.01-SNAPSHOT


I thought that perhaps this may have been related to the fact that we use maven and maybe that was throwing another complication into the mix.  As it turns out, if you don't provide a location of the deployed war to the configurations, GWT tries to access what it thinks the location.  The directory does in fact not exist, nor is it where my deployed war lives.  After some random clicking around and setting the directory to different places that may make sense, I figured out what it was looking for.  So, in summary, this is another way to get the GWT debugger to work by manually configuring things:

  1. In eclipse, right click on your project and choose Debug as -> Debug Configurations ...
  2. In the left hand panel, scroll down to "Web Application", select it and then click new.
  3. Click on the New_configuration to edit it
  4. In the Main tab, change the name of the configuration to something meaningful to you so you know what this configuration is for.  The project should be pre-filled with the name of the GWT app that you right clicked over. If it isn't, or it is not correct, click on the browse button to select the project.  This was a slight point of confusion for me, what project should I use? The code base I work on is very large with many modules. I chose the entry point into the application for the client as the GWT project ( and I chose correctly it seems ). I didn't know what main class to use or read up on what my options were, so I just left the default value.
  5. Now go to the Server tab.  Because I am running tomcat locally on my machine, I do not want to use the embedded server, so uncheck this option.
  6. Now go to the GWT tab.  Type in the name of the URL you would use in a browser to access your application. If you don't see the URL field, you probably forgot to uncheck the use embedded server in the previous step.  In my case, my application is running on https and the url needs to reflect this.  Additionally, note that the class that has your entry point should show up here.
  7. Now go to the Arguments tab.  Here's where I ended up flailing for a bit.  At the beginning of the program arguments, add the following:
    -war /opt/tomcat6/webapps/helloWorld/
    You should use the fully qualified path to the your deployed application folder (not the *.war file)
  8. Finally, you should probably add all the source for your project if you want to step through the debugger to the Source tab.
And that's it!  When you click on debug, you should see a tab on your screen where your console is that says "Development Mode".  One other probably obvious thing is that you want to start up tomcat first before clicking debug.  After this, you'll see in the Development Mode console a URL you can copy and paste into a browser and use for debugging the client side.

Yes, I know, this should be simple and straight forward, but I figured if I was having trouble ... I'm sure (hopefully) someone out there on the interwebs is having similar troubles.

Tuesday, January 4, 2011

Remote debugging webapp in Tomcat (Rhel) through Eclipse (Ubuntu)

Background to my current issue:
There appears to be something odd going on the server side of our network code. Our server is a virtual machine hosted on GoGrid and the oddness is only occurring in release 1.14 and later of our network code.  The current trunk of our code is 1.16-SNAPSHOT and the network code on the vm is 1.15 (release).

I've spent the better of today getting right set of convocations together for my particular set of system set ups.  Specifically:
Locally
* Ubuntu 10.04 (Lucid Lynx)
* Eclipse 3.5

Server Side
* Rhel 5.4
* Tomcat 6

Hopefully the following represents an accurate list of steps to assist anyone else with setting up a remote debugging of a webapp running on a Tomcat elsewhere through Eclipse on your local machine.

  • Setting up tomcat to start up in debug mode:
    • Most of the websites I came across suggest adding a command after the script:

       [host]$ catalina.sh jpda start 
      (Mulesoft's blog)
    •  
    • For my particular set up, I did not have a catalina.sh script file to manipulate.  Instead, Rhel's installation of Tomcat6 creates a conf folder and a conf file where the options are set.  In my case, the specific file name is tomcat6.conf and was found in ~tomcat6/conf/
      • In this file, I added the following lines after setting where the installation lives (noting that this should be the first JAVA_OPTS set):
         # Java option to turn on debugger FIRST
        JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" 

        NB: that there can not be any spaces around the initial "=". The above is NOT equivalent to:
        JAVA_OPTS = "-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" 

    • Now it's time to restart (bounce) the tomcat for the tomcat to pick up the changes in the JVM arguements:
      [host]$ /etc/init.d/tomcat6 restart 

  •  Setting up the server to listen to the port that has been designated in the above step for the debugger (in this example, 8000, see the numbers after "address")
    • Now the appropriate ports need to be opened on the iptables:
      [host]$ vim /etc/sysconfig/iptables 

      And add this line into the file and save it:
      -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 8000 -j ACCEPT
      

      This line should go along with the other similar statements in the file. Once the file has been saved, the iptables need to be restarted for the changes to take affect:
      [host]$ /etc/init.d/iptables restart

  • Since my server is hosted on GoGrid, I know that they have a firewall in place. The next step is to create an ssh tunnel to my server. For the sake of usability, I installed "Gnome SSH Tunnel Manager - a front-end to ssh tunneling" and added the information for my server and opened up the tunnel with the followinig for the properties:
    • Name: GoGrid 252 [This can be anything that is easy for you to recognize]
    • Login: me [This is the login you would use to login to the server]
    • Host: ###.##.###.252 [This is the IP address of the server]
    • Port: 22 [This is the port that you have designated on your server as your ssh port, default is 22]

  • Finally, on my local machine in Eclipse, I had to do the following:
    • I needed the specific version of the code base project opened that the server was running.  In this case, I had been working on 1.16 SNAPSHOT, which I needed to close and open up the 1.15 release that is running on the server.
    • Click on any file in the project that contains the webapp code
    • From the Eclipse menu, navigate: Run -> Debug Configurations
    • In the left handle panel, navigate up to Remote Java Applications, right click over it and select New from the pop-up menu.
    • In the right hand panel you should now see 3 tabs and a name field.  The name field is for your reference and will show up on the left hand panel for you to select later.  Under the Connect tab you should fill in the following:
      • Project: [The project containing the source code for the webapp you are trying to debug in the remote Tomcat]
      • Connection Type: Standard (Socket Attach)
      • Host: ###.##.###.252 [This is the IP address of the server]
      • Port: 8000 [This is the designated debugging port that was set up on the server]
    • Click Apply and then Debug

  • In the source code for the webapp, put a breakpoint somewhere that you know will be hit and then send a request to your tomcat.  You should see be able to now debug in Eclipse.

And that summarizes up what I did to get the debugging to work on my local machine for a remote webapp on Tomcat.

Here are some links to blogs which assisted me in getting to this point:

http://forums.alfresco.com/en/viewtopic.php?f=10&t=1914&start=15
http://wiki.apache.org/tomcat/FAQ/Developing?highlight=%28CategoryFAQ%29

Hope this helps :).