Jump to content


Debugging Tomcat In Jcreator


  • Please log in to reply
No replies to this topic

#1 E-E-R

E-E-R

    Advanced Member

  • Members
  • PipPipPip
  • 1,367 posts
  • Gender:Male
  • Location:The Netherlands
  • Interests:Programming, Gaming, DC

Posted 20 December 2005 - 10:02 PM

Debugging TomCat using JCreator V3
By EER

Introduction
Regularly people are inquiring at the JCreator board (http://www.jcreator.com/forums/) how to debug their JSP files using JCreator. As it is possible in other IDE's, I had no reason to assume that it wouldn't work with JCreator.
Before writing this guide, I have no experience with TomCat at all. I am an experienced JCreator user, and have worked as tech support for a local hardware store, so I have some knowledge about windows in general.
This guide is still quite beta, because I do not program Servlets, I have very limited testing possibilities. Feedback is always welcome, please  reply in the forumthread.

Requirements
Before you proceed reading this guide, please check whether you meet all requirements. In this guide I will assume you have the following programs installed:

* Windows 2000 or XP (I have not tested with 9x/ME or Linux)
* Tomcat 4.1 (I have not tested with other releases)
* JCreator Pro V3 (LE does not include debugging nor JSP support)

First step: Configure TomCat
To use remote debugging with TomCat, you will have to add some environment variables.
Windows
There are two ways to do this in Windows, the first is temporary and is only remembered in the current windows session.

Open a command console and enter the following:
CODE
set JPDA_ADDRESS=8000

Then:
CODE
set JPDA_TRANSPORT=dt_socket

Then:
CODE
set JAVA_HOME=<Your java homedir>

And finally:
CODE
set


The output window should look like something in image 1.The important thing is that the last command shows a list of environment variables, make sure that both JDPA_ADDRESS and JDPA_TRANSPORT are  defined in that list.

The second way is to create user environment variables, which are remembered "forever" on this computer, and as the name suggests are user-specific. Also, it is easier for not-technical users as it is GUI oriented.

Open the properties window of "My Computer" (by selecting it and pressing Alt+Enter), browse to the tab "Advanced" and (left-)click the "Environment Variables" button. You will see a list of User and System variables. The System variables are not user specific, but need Administrator rights to edit. Click one of the New buttons, you will see a new window where you can input the name and value of the variable.
In the window make a new variable with the name:
JPDA_ADDRESS
and the value:
8000

Then, make another Environment Variable by clicking the same New button input the following name:
JPDA_TRANSPORT
and the value:
dt_socket

Finally, make another Environment Variable called:
JAVA_HOME
with your java homedir as value.

All three variables should now be in the list.

If both variables have been correctly configured, you can run TomCat by using the batch file "Catalina.bat" in the Tomcat\bin\ directory.

To do this, switch back (or open) to the console window and move to the Tomcat\bin directory. This can be achieved by entering the following:
CODE
cd "\Program Files\Apache Group\Tomcat 4.1\bin"

The path should of course be replaced by the path where you have installed TomCat.

Run TomCat using the Catalina batch file with some additional parameters, required for debugging, you can do this by entering the following in the console window:
CODE
catalina jpda start

This command will start TomCat, while listening for a debugger on the configured JPDA Adress: 8000.

So now we have a TomCat instance that is ready for debugging.

Linux
Apparently, people are running Tomcat on Linux. Whatever suits you I guess ;)
The linux information has not been tested or confirmed in any way by me, it is an interpretation of the directions given in a blog entry I came across: http://www.wiersma.org/blog/?page_id=9

To set Environment variables in Linux, open a console window (like bash) and enter the following lines:
CODE
export JPDA_TRANSPORT=\"dt_socket\"
export JPDA_ADDRESS=\"8000\"
export JAVA_HOME=<your java homedir>


Now it is time to start the TomCat server, by moving to the \bin directory of tomcat:
CODE
cd tomcatdir\bin


And then running catalina.sh jpda start as follows:
CODE
sh ./catalina.sh jpda start


You will now probably have TomCat running while it listens for debuggers on tcp port 8000.

Windows & Linux
You will probably by now have something like the following on your screen:
user posted image

Second step: Configuring JCreator
JCreator has the "feature" to not even try to start the debugger if no suitable main method or HTML file is found. Obviously, this is always the case when developing Servlets and such.
Currently the workaround is to create a dummy main-class in your project so JCreator will not complain about not finding any.

Create a file "Dummy.java" in your project containing the following code:
CODE
public class Dummy{
public static void main(String[] args){
 // do nothing
}
}

You do not even have to compile this class, as we are just using it to fool JCreator in starting the debugger.

As we all know, the debugger does not attach to TomCat by itself. You will have to configure the JCreator debugger profile. To do this, open the options dialog by clicking Configure > Options.

In the options dialog, go to the JDK Tools screen and select the 'Debugger' tool type. The list will initially only show '<Default>', which does not suit our needs.Create a New profile by clicking 'New…' on the right.

user posted image

Call the new profile 'TomCat' (or any other name that suits you). Uncheck all checkboxes in the first tab (Command). For the command, fill in the following:
CODE
"$[JavaHome]\bin\jdb.exe" -connect com.sun.jdi.SocketAttach:hostname=127.0.0.1,port=8000

Replace 127.0.0.1 by the IP-Address of your TomCat Server, a hostname may work as well.

user posted image

On the Application parameters tab and the Applet parameters tab, clear the textbox.

Click OK to save your changes and click OK to close the options screen.

Now go to the Properties window (Project > Properties) of your project and select the second tab "JDK Tools". Select the Debugger JDK Tool Type. If you have followed the instructions correctly, you will have two configurations available. Check the checkbox next to "TomCat" and click OK to save your changes.

The next time you run the debugger in the project, it will attach to the running TomCat Process. Make sure you have compiled your servlet with the -g compiler flag (include debug info) or JCreator cannot set the breakpoints, as the server will claim the given class does not have line numbers.

There you go, you're all set to debug Servlets from JCreator. If you have any suggestions, experience in setting up Tomcat in Linux, questions, or other comments, feel free to post them below :)

Special Thanks to:
Arjen Wiersma, for creating an inspiring blog entry: http://www.wiersma.org/blog/?page_id=9
Xinox Software, for creating JCreator :)
Jeroen van de Pol, for testing this guide before I posted it :)
Tomcat developers, excellent howto: http://tomcat.apache.org/faq/development.html
It just misses JCreator ;)

© EER - 2005. Please do not reproduce without asking first.
"Many are persistently in pursuit of the way they have chosen; few in pursuit of the goal"