Setting up Visual J++ to allow dubgging of Tomcat JSPs and Servlets

Installation steps:

Important Note

In all of my examples, and in my own work, I just used relative directory names, like \tomcat\.... If tomcat, your project files, and your JDK are not on the same drive, you will need to include drive letters where appropriate, in the classpaths, output directories, etc. So, you would put D:\tomcat\... instead.

General (only need be done once)

  1. Install tomcat (by extracting it into it's own directory - I use "\tomcat"), and verify that it works.

  2. Create/grab the .zip file with the runtime classes for the MS VM: The name of the zip file should be found in the registry key:

      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Code Store Database\Global Namespace\Java Packages\java\util

    The file should be in the C:\WINNT\java\packages\ directory (I do not know where it will be on Win9x, I could check on this at home sometime). I just quickly opened each of those until I found the one with the java/util classes in it before I knew about the registry key, and this may be faster than looking through the registry.

    Copy this file to your tomcat\lib directory, and rename it to msrt.zip (it will originally be named with a unique combination of chracters and numbers).

  3. Make Sun's java.text.MessageFormat.class file accessible: First, you need to extract it from the \jdk1.2.2\jre\lib\rt.jar file (rename it to a .zip and use WinZip if you'd like). Next, you need to make it accessible to VJ++; there are a few ways to do this. One is to make a java\text directory off of one of the directories in your classpath *before* the msrt.zip. Another is to add it to msrt.zip so that it overwrites MS's (don't worry, MS's will still be availible in the original .zip file in your c:\winnt\java directory). The easiest way to do this (making sure that the directory structure is correct) is to create a folder off of \tomcat\lib named \tomcat\lib\temp and in it put the \java\text\ directory structure, containing only the one MessageFormat.class file, and then drag temp to your msrt.zip file (using WinZip) and it will add it, overwriting the MS one.

    This class file is needed because, in tomcat, Hashtable objects are passed to the MessageFormat class. Looking at the Sun docs, it doesn't even appear this is valid, but it works with both the Sun and Symantec class libraries and not MS's so we need to include this.

Project specific (need to be done with every project you create)

  1. Create a project: Set the project's output path to the appropriate directory. For this example, I am assuming tomcat is installed in \tomcat, and my webapp will run from \tomcat\webapps\test\. The actual .java files and project file can be anywhere (\src\test in my case). In the VJ++ Project Properties (Alt-F7), under the Compile tab, set the Output Directory to \tomcat\webapps\test\WEB-INF\classes. Add all of your own files to your project at this point also.

  2. Set up the command line: In the VJ++ Project Properties window, under the Launch tab, choose the radio button for Custom. Change the program from WJView.exe to JView.exe. Change the Arguments to
    /p /cp:p "<JAVAPACKAGES>" org.apache.tomcat.startup.Tomcat -home \tomcat

  3. Set up the classpath: The classpath needs to contain an interesting combination of both MS's and Sun's run-time classes. MS's where they work since the MS JVM needs them, and Sun's where MS's aren't adequate or where MS's doesn't even include a specific class. In the VJ++ Project Properties window, under the Classpath tab, you need to add these entries, so they are included in this order: (VJ++, by default, adds to the top of the list, so if you start adding these from the bottom up, they will end up in the correct order)
    \tomcat\lib\xml.jar
    \tomcat\lib\jasper.jar
    \tomcat\lib\webserver.jar
    \tomcat\lib\ant.jar
    \tomcat\lib\servlet.jar
    \tomcat\lib\msrt.zip
    \jdk1.2.2\jre\lib\rt.jar
    \jdk1.2.2\lib\tools.jar
    
    Specific notes on the ordering: All of the tomcat stuff should be first, since there should be no name colisions, but if there are, we want to use the tomcat classes. Next needs to be Sun's MessageFormat.class. If you just have this in a directory somewhere, you would insert that directory name between servlet.jar and msrt.zip. Next needs to be the MS RunTime libraries, these *must* be before the Sun RunTime libraries, otherwise the MS JVM dies. Last is all of the sun stuff that isn't in the MS libraries (including javac in tools.jar). If there is a way to configure tomcat/jasper to use a different compiler, you could get rid of the need for tools.jar.

    You can also put these classpath entries in the command line (where "<JAVAPACKAGES>" is), but be warned: there is a limit on how many characters long the command line in VJ++ can be, and it doesn't tell you when you exceed it, just behaves weird.

  4. You're now ready to go! You should be able to compile your project, which now puts the .class files into the appropriate tomcat directory. Then, when you run your project, it launches tomcat, and you should see the tomcat startup messages in the console. Now, you can set breakpoints in your servlet or processed .jsp code (the .java files in the \tomcat\work\ directory), pull up your browser, and debug!

Problems I've ran into/are still running into

  • I tried copying the equivalent msrt.zip file from another computer, and I noticed that all of the files had newer timestamps than mine did. Using this one, I was unable to run .jsp files. The date on all of the files in my .zip are 3/23/99. If you are running into problems, and your files are not of this date, you might want to try getting them. The are on N:\oft\jimb\msrt.zip on UPI's internal LAN, and availible on the web upon request from me.

Also availible is a sample empty project file that has all of the classpath and project info preconfigured, assuming all of the folders are on the same drive.

Notes.. .

  • . .. on JSPs: This method *does* work for JSPs too! If you are not using JSPs, the steps are a lot simpler, you can skip all of the "General" steps, and in the classpath, you don't need the sun jre\rt.jar file.

  • . .. on debugging Tomcat: This method cannot be used to debug/develop the entirety tomcat itself, since a large portion of the tomcat code won't compile in VJ++, due to either newer libraries in Sun's SDK, or things unsupported in MS's, or maybe something else. You *can* put breakpoints in tomcat's code, and change most of the files, you just can't do a full build.

  • . .. on ClassPaths in VJ++: MS VJ++ doesn't look at the %CLASSPATH% environment variable like most other JVMs and compilers do, it uses it's own, internal settings, and settings stored in the registry.

  • . .. on directories: If you initially have problems with directories and Tomcat, try specifying absolute paths. So something like this might be your arguments to JView.exe:
    /p /cp:p "" org.apache.tomcat.startup.Tomcat -home "C:/Program Files/Jakarta/Tomcat"
    (Note the use of / instead of \)

Specific versions used:

JDK 1.2.2
Tomcat 3.1
Microsoft Visual J++ 6.0
Visual InterDev 6.0 (SP3)

Explanations:

  • JMV - Java Virual Machine
  • MS's JVM - specifically JView.exe or WJView.exe (for graphical java apps)
  • RT - Run Time
  • MS's RT classes - Those classes that make up the standard java package, java.util, java.lang, java.text, etc. Found using the method described in step 1.
  • Sun's RT classes - Those included in the JRE, in the jre\lib\rt.jar file
This document © 2000 Jimb Esser, Universal Pensions, Inc.
Distribute and modify freely, give credit where due.
Please email any comments or suggestions for this doc to Jimb Esser.
Special thanks to Tal for feedback.


Back to Jimb Esser's Technical Docs