Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Add question list to start.

...

This section of the FAQ discusses common questions related to Tomcat development.

Questions

  1. Hacking
    1. How do I start hacking Tomcat in Eclipse?
  2. Debugging
    1. How do I configure Tomcat to support remote debugging?
    2. How do I remotely debug Tomcat using Eclipse?
    3. How do I remotely debug Tomcat using NetBeans?
  3. Other
    1. How do I change the monitoring interval for modified resources and application reloading?
    2. Official Eclipse IDE Web Tools FAQ for Tomcat

Answers

Hacking

...

How do I start hacking Tomcat in Eclipse?

Briefly:

No Format

$ svn checkout http://svn.apache.org/repos/asf/tomcat/trunk
  (or whatever branch you want: clearly, this would be better
  to do directly from within Eclipse but it's easier to describe
  as a command)

$ cd trunk

$ echo "base.path=/path/to/where/tomcat/can/put/its/3rd-party/libs" > build.properties

$ ant ide-eclipse

Then, in Eclipse, go to Preferences | Java/Build Path/Classpath Variables and set the following variables:

No Format

ANT_HOME=path to your Ant install (where lib/ant.jar can be found)
TOMCAT_LIBS_BASE=[whatever you set base.path to above]

If you look in (project root)/res/ide-support/eclipse/java-compiler-errors-warnings.txt, you'll see a set of compiler warnings and import organization rules that you will have to set up manually in your project. If you set those up properly, you are more likely to submit cleaner patches.

A full explanation for Tomcat in Eclipse can be found here:

Debugging

  1. Wiki Markup
    \[#Q1 How do I configure Tomcat to support remote debugging?\]
  2. Wiki Markup
    \[#Q2 How do I remotely debug Tomcat using Eclipse?\]
  3. Wiki Markup
    \[#Q3 How do I remotely debug Tomcat using NetBeans?\]
  4. Wiki Markup
    \[#Q4 How do I change the monitoring interval for modified resources and application reloading?\]

Answers

AnchorQ1Q1How do I configure Tomcat to support remote debugging?

The short answer is to add the following options when the JVM is started:

...


...

-Xdebug

...

-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

...


There are a number of ways you can do this depending on how you normally start Tomcat:

  • If you are using shell scripts to start Tomcat, start it with the following command:
    No Format
    
     catalina jpda start
     
    It will start Tomcat so that a remote debugger can be connected to port 8000.
    The above mentioned options can be provided by setting certain environment variables. See the comments at the top of catalina.sh or .bat file for details.
    For example, the port number and JPDA transport implementation can be set with Set environment variables JPDA_ADDRESS=8000 and JPDA_TRANSPORT=dt_socket and then start tomcat using catalina jpda start.
  • If you run Tomcat using service wrapper, add the above JVM options before any other JVM options. Check the check the documentation for the service wrapper to determine how to set the required JVM options.
  • If you start Tomcat from within an IDE, check the documentation for the IDE to determine how to set the required JVM options.

...

Whilst this is very useful in development it should not be used in production because of both security and performance implications.anchor

Q2Q2How do I remotely debug Tomcat using Eclipse?

This answer assumes that you have a project set up with all of the fixings and have some idea of what you are 're doing in this respect. If not then that is thats really outside the scope of this topic and more in the scope of you need needing to go to http://eclipse.org eclipse.org and read up on how to use your IDEide, and maybe practice a little bit before you come back to this. We are 're also going to assume that you have some idea of what a debugger is and how to use one.

Make sure

...

tomcat is started

...

and that your app is deployed

...

and the sources

...

, etc are all defined as resources in your app. If you have a servlet or something, set a breakpoint where

...

its sure to hit on the next request.

...

Go to "Run->Debug

...

...". Click on "Remote Java Applications", then click "New". Type in the title and all.

...

Notice that port 8000 from the Tomcat instructions. Save and run.

...

Eclipse will connect to the

...

VM that Tomcat is running under. Wow, that was easy!

...

Now go type the url to submit to your servlet or whatever in your browser. Boom you hit the breakpoint right? Have fun!

AnchorQ3Q3How do I remotely debug Tomcat using NetBeans?

This answer assumes that you know how to work with have correctly set up a NetBeans Project, and also project and that you know how to use the NetBeans debugger. If not, please go to http://www.netbeans.org/kb/using-netbeans/40/debug.html and read up on how to use NetBeans and its debugger.Starting with Tomcat trunk revision 1484409, the Tomcat source includes Ant tasks to configure your source directory as a NetBeans Free-Form Project. After you have successfully run Ant with the default build target (deploy), you can then run the ide-netbeans target. This task will configure your sandbox copy of Tomcat so the source can be inspected, maintained and debugged under the NetBeans IDE. You should follow the detailed instructions in the README.txt file that will have been installed in your new nbproject directory.

Make sure that Tomcat is started in debug mode as described above, that your application is deployed, and that the sources are all defined as resources in your application. If you have a servlet or JSP file, set a breakpoint where you think a problem might be occurring. Go to "Run->Attach Debugger". A dialog pops up to let you specify the following options:

  • Debugger: JPDA Debugger
  • Connector: SocketAttach
  • Host: The IP address of the host your Tomcat installation is running on (127.0.0.1 if it is your local machine).
  • Port: The port of your Tomcat debugging interface, which should be 8000 if you've followed the instructions above.

When you press OK, you have a debugging connection very similar to local debugging.

Note that NetBeans has a second option – you can debug JSP files and servlets locally using a Tomcat server that is bundled with the IDE. When you debug a JSP file or servlet in the IDE, the bundled Tomcat server automatically starts in debug mode, and the debugger connects to it.The Tomcat NetBeans targets have not yet been back-ported to Tomcat 7. You can copy the files from your copy of the trunk and they should only require minimal editing of paths to work with older versions of Tomcat.

Other

AnchorQ4Q4How do I change the monitoring interval for modified resources and application reloading?

Monitoring interval for application reloading is controlled by the backgroundProcessorDelay property on Context element or on its parent containers: Host and Engine. See Tomcat Configuration Reference for details. By default there is a single background processing thread that is run by Engine. See its configuration for the default delay value.

Interval that controls reloading of the changed JSP pages is set in the Jasper configuration in web.xml.

...

Official Eclipse IDE Web Tools FAQ for Tomcat

Eclipse IDE has support for development of Web applications and running them on Apache Tomcat. This support is provided by Eclipse Web Tools Platform Project. An easy way to get Web Tools is to download "for Java EE Developers" edition of Eclipse IDE.

The Web Tools project has a FAQ page.

  • WTP Tomcat FAQ
  • In Eclipse Help see "Web Tools Platform User Guide" > "Using the server tools" > "Testing and publishing on your server"

CategoryFAQModify the checkInterval attribute value on the relevant Loader element in your web application configuration file (yourapp.xml), or in the main configuration file %CATALINA_HOME%/conf/server.xml if that is the one you're using. For more information, please see the http://tomcat.apache.org/faq/config/loader.html Loader configuration reference.