Set remote Debug Method in Tomcat

Source: Internet
Author: User
Tags stop script

[Switch] set the remote Debug Method in Tomcat

Http://hi.baidu.com/huamarco/blog/item/75c3f2a411e3ebf29152ee34.html

From: http://blog.csdn.net/zmxj/

What is remote debugging? When debugging Java code for a web project, we need to integrate your Tomcat server with your development tools (such as JBuilder, or you need some plug-ins to support the tool (such as myclipse in eclipse). These methods are implemented locally, that is, your development tool and tomcat run on the same server, if your development tools and servers are no longer on one machine, you need to implement remote debugging.

Implementation Method:
Add the following settings to the Catalina. BAT file of Tomcat. Of course, the set catalina_opts variable should be used before. This is to set some virtual machine parameters during Tomcat startup so that the server can allow remote connection. Address = 5888 indicates the port number for remote connection and can be set to any other non-conflicting port. Other application servers, such as WebLogic, should be able to set these parameters. If you are interested, you can test them.

Set catalina_opts =-server-xdebug-xnoagent-djava. compiler = none-xrunjdwp: Transport = dt_socket, Server = Y, suspend = N, address = 5888
This is OK. Restart Tomcat and start it independently, instead of starting it in the plug-in of elasticsearch. Open the debug settings window in eclipse, select remote Java application, create a debug item, enter the Server IP address and the configured port number, and click OK to enter the debug status. You can also set remote Java application in JBuilder.

Tomcat remote debugging

Http://xw302.javaeye.com/blog/246885

Method 1: Applicable to tomcat6

Modify startup. BAT to start in the following column at the end

Set jpda_address = 8000
Set jpda_transport = dt_socket
Call "% executable %" JPDA start

For other remote Java debugging, add the following parameters to the JVM:
-Xrunjdwp: Transport = dt_socket, Server = Y, address = 8000, suspend = y

Method 2: Applicable to Tomcat 5
Modify Catalina. bat

Set _ execjava = % _ runjava %
Set mainclass = org. Apache. Catalina. startup. Bootstrap
Set action = start
Set security_policy_file =
Set debug_opts =
Set JPDA =
Set java_opts =-xdebug-xnoagent-djava. compiler = none-xrunjdwp: Transport = dt_socket, address = 9999, suspend = N, Server = y

Reference
Tomcat remote debugging http://onlydo.javaeye.com/blog/120258
(Switch) Tomcat STARTUP script Catalina. Sh
Http://bluestar.javaeye.com/blog/181464
Keyword: Tomcat Startup Script
1-Overview
The script Catalina. Sh is the most critical script for starting and disabling Tomcat servers.
In addition, startup. SH and shutdown. Sh both use different parameters to call the script.
The script is used as follows (derived from the script itself ):

Echo "Usage: Catalina. Sh (commands ...)"
Echo "commands :"
Echo "Debug start Catalina in a debugger"
Echo "debug-security debug Catalina with a security manager"
Echo "embedded start Catalina in Embedded mode"
Echo "JPDA start Catalina under JPDA Debugger"
Echo "Run start Catalina in the current window"
Echo "Run-security start in the current window with security manager"
Echo "start Catalina in a separate window"
Echo "start-security start in a separate window with security manager"
Echo "Stop Catalina"
2-script analysis

#! /Bin/sh
#===================================================== ======================================
# Set the correct environment variables and system information, and start or stop the Tomcat server
# The specific operations are as follows:
# Use the command line parameter as the real parameter of argS and call org. Apache. Catalina. startup. Bootstrap. Main (string [])
#===================================================== ======================================

#-----------------------------------------------------------------------------
# Start/stop script for the Catalina Server
#
# Environment variable prequisites
#
# Catalina_home may point at your Catalina "build" directory.
#
# Catalina_base (optional) base directory for Resolving Dynamic portions
# Of a Catalina installation. If not present, resolves
# The same directory that catalina_home points.
#
# Catalina_opts (optional) Java runtime options used when the "Start ",
# "Stop", or "run" command is executed.
#
# Catalina_tmpdir (optional) directory path location of temporary directory
# The JVM shocould use (Java. Io. tmpdir). defaults
# $ Catalina_base/temp.
#
# Java_home must point at your Java development kit installation.
#
# Java_opts (optional) Java runtime options used when the "Start ",
# "Stop", or "run" command is executed.
#
# Jpda_transport (optional) JPDA transport used when the "JPDA start"
# Command is executed. The default is "dt_socket ".
#
# Jpda_address (optional) Java runtime options used when the "JPDA start"
# Command is executed. The default is 8000.
#
# Jsse_home (optional) may point at your Java Secure Sockets Extension
# (JSSE) installation, whose jar files will be added to
# System class path used to start Tomcat.
#
# Catalina_pid (optional) path of the file which shoshould contains the PID
# Of Catalina startup Java Process, when start (fork) is used
#-----------------------------------------------------------------------------

# OS specific support. $ VaR _ must _ be set to either true or false.

Cygwin = false
Case "'uname'" in
Cygwin *) cygwin = true ;;
Esac
# PRG is the name of the script to be executed. It can be considered as PRG = "Catalina. Sh" or a symbolic chain pointing to the script.

PRG = "$0"

# After processing the PRG, The PRG becomes ????

While [-h "$ PRG"]; do
Ls = 'LS-LD "$ PRG "'
Link = 'expr "$ ls": '. *->/(. */) $''
If expr "$ link": '. */. *'>/dev/NULL; then
PRG = "$ link"
Else
PRG = 'dirname "$ PRG" '/"$ link"
Fi
Done

# Prgdir is the Directory Name of the PRG.

Prgdir = 'dirname "$ PRG "'

# Run $ catalina_home/bin/setenv. Sh to set the environment variable
# [-R filename] indicates whether the object exists and is readable.

Catalina_home = 'CD "$ prgdir/.."; pwd'
If [-R "$ catalina_home"/bin/setenv. Sh]; then
. "$ Catalina_home"/bin/setenv. Sh
Fi
# For cygwin, make sure all path names comply with the Unix format

If $ cygwin; then
[-N "$ java_home"] & java_home = 'cygpath -- Unix "$ java_home "'
[-N "$ catalina_home"] & catalina_home = 'cygpath -- Unix "$ catalina_home "'
[-N "$ catalina_base"] & catalina_base = 'cygpath -- Unix "$ catalina_base "'
[-N "$ classpath"] & classpath = 'cygpath -- path -- Unix "$ classpath "'
[-N "$ jsse_home"] & jsse_home = 'cygpath -- path -- Unix "$ jsse_home "'
Fi

# Set the classpath variable used to initialize systemclassloader by executing the script setclasspath. Sh.
# Note: The Script setclasspath. Sh changes the original $ classpath variable and sets it:
# Classpath = $ catalina_home/bin/Bootstrap. jar: $ java_home/lib/tools. Jar
# Bootstrap. jar is the package org. Apache. Catalina. startup,
# Contains the startup method org. Apache. Catalina. startup. Bootstrap. Main (string [] ARGs)
# Tools. jar contains the javac compiler, which is used to compile JSP files into servlet class

If [-R "$ catalina_home"/bin/setclasspath. Sh]; then
Basedir = "$ catalina_home"
. "$ Catalina_home"/bin/setclasspath. Sh
Else
Echo "cannot find $ catalina_home/bin/setclasspath. Sh"
Echo "this file is needed to run this program"
Exit 1
Fi
# Add some jar files after the classpath Environment Variables
# [-N string] determine whether the string length is not 0; [-Z string] determine whether the string length is 0
# They can be used to determine whether an environment variable has been set

If [-n "$ jsse_home"]; then
Classpath = "$ classpath": "$ jsse_home"/lib/jcert. jar: "$ jsse_home"/lib/jnet. jar: "$ jsse_home"/lib/JSSE. Jar
Fi
Classpath = "$ classpath": "$ catalina_home"/bin/Bootstrap. Jar

# Specify the catalina_base variable
# If catalina_base has no value, make catalina_base = $ catalina_home

If [-z "$ catalina_base"]; then
Catalina_base = "$ catalina_home"
Fi
# Specify the catalina_tmpdir variable
# If catalina_tmpdir has no value, make catalina_tmpdir = $ catalina_base/temp

If [-z "$ catalina_tmpdir"]; then
# Define the java. Io. tmpdir to use for Catalina
Catalina_tmpdir = "$ catalina_base"/temp
Fi
# For cygwin, convert the path name to Windows format before executing the Java program

If $ cygwin; then
Java_home = 'cygpath -- path -- Windows "$ java_home "'
Catalina_home = 'cygpath -- path -- Windows "$ catalina_home "'
Catalina_base = 'cygpath -- path -- Windows "$ catalina_base "'
Catalina_tmpdir = 'cygpath -- path -- Windows "$ catalina_tmpdir "'
Classpath = 'cygpath -- path -- Windows "$ classpath "'
Jsse_home = 'cygpath -- path -- Windows "$ jsse_home "'
Fi

# Display information and execute the command
Echo "using catalina_base: $ catalina_base"
Echo "using catalina_home: $ catalina_home"
Echo "using catalina_tmpdir: $ catalina_tmpdir"
Echo "using java_home: $ java_home"

# ...... When the execution of the Catalina. Sh parameter is JPDA ......

If ["$1" = "JPDA"]; then
If [-z "$ jpda_transport"]; then
Jpda_transport = "dt_socket"
Fi
If [-z "$ jpda_address"]; then
Jpda_address = "8000"
Fi
If [-z "$ jpda_opts"]; then
Jpda_opts = "-xdebug-xrunjdwp: Transport = $ jpda_transport, address = $ jpda_address, Server = Y, suspend = N"
Fi
Catalina_opts = "$ catalina_opts $ jpda_opts"
Shift
Fi

# ...... When the Catalina. Sh parameter is debug ......

If ["$1" = "debug"]; then
Shift
If ["$1" = "-Security"]; then
Echo "using security manager"
Shift
Exec "$ _ runjdb" $ java_opts $ catalina_opts/
-Djava. endorsed. dirs = "$ java_endorsed_dirs"-classpath "$ classpath "/
-Sourcepath "$ catalina_home"/.../jakarta-tomcat-4.0/Catalina/src/share/
-Djava. Security. Manager/
-Djava. Security. Policy = "$ catalina_base"/CONF/Catalina. Policy/
-Dcatalina. base = "$ catalina_base "/
-Dcatalina. Home = "$ catalina_home "/
-Djava. Io. tmpdir = "$ catalina_tmpdir "/
Org. Apache. Catalina. startup. Bootstrap "$ @" Start
Else
Exec "$ _ runjdb" $ java_opts $ catalina_opts/
-Djava. endorsed. dirs = "$ java_endorsed_dirs"-classpath "$ classpath "/
-Sourcepath "$ catalina_home"/.../jakarta-tomcat-4.0/Catalina/src/share/
-Dcatalina. base = "$ catalina_base "/
-Dcatalina. Home = "$ catalina_home "/
-Djava. Io. tmpdir = "$ catalina_tmpdir "/
Org. Apache. Catalina. startup. Bootstrap "$ @" Start
Fi

# ...... When the parameter for executing Catalina. Sh is embedded ......

Elif ["$1" = "embedded"]; then
Shift
Echo "embedded classpath: $ classpath"
Exec "$ _ runjava" $ java_opts $ catalina_opts/
-Djava. endorsed. dirs = "$ java_endorsed_dirs"-classpath "$ classpath "/
-Dcatalina. base = "$ catalina_base "/
-Dcatalina. Home = "$ catalina_home "/
-Djava. Io. tmpdir = "$ catalina_tmpdir "/
Org. Apache. Catalina. startup. Embedded "$ @"
# + ---------------------------------------------------- +
# | ...... When the Catalina. Sh parameter is run, ...... |
# | Start the Tomcat server in the current window !!! |
# + ---------------------------------------------------- +

Elif ["$1" = "run"]; then

# Remove the run Parameter

Shift

# If the parameter is run-security, start Security Manager

If ["$1" = "-Security"]; then
Echo "using security manager"
Shift
Exec "$ _ runjava" $ java_opts $ catalina_opts/
-Djava. endorsed. dirs = "$ java_endorsed_dirs"-classpath "$ classpath "/
-Djava. Security. Manager/
-Djava. Security. Policy = "$ catalina_base"/CONF/Catalina. Policy/
-Dcatalina. base = "$ catalina_base "/
-Dcatalina. Home = "$ catalina_home "/
-Djava. Io. tmpdir = "$ catalina_tmpdir "/
Org. Apache. Catalina. startup. Bootstrap "$ @" Start
# If the parameter is run, start the Tomcat server in this window.
# In this window, execute to fork a new process to start Tomcat. The current process is the parent process of Tomcat.
# The Tomcat startup class is org. Apache. Catalina. startup. Bootstrap. Main ("START ");

Else
Exec "$ _ runjava" $ java_opts $ catalina_opts/
-Djava. endorsed. dirs = "$ java_endorsed_dirs"-classpath "$ classpath "/
-Dcatalina. base = "$ catalina_base "/
-Dcatalina. Home = "$ catalina_home "/
-Djava. Io. tmpdir = "$ catalina_tmpdir "/
Org. Apache. Catalina. startup. Bootstrap "$ @" Start
Fi
# + ---------------------------------------------------- +
# | ...... When the Catalina. Sh parameter is set to start, ...... |
# | Start the Tomcat server in a new window !!! |
# + ---------------------------------------------------- +

Elif ["$1" = "start"]; then

# Remove the start parameter

Shift

# Create a file (if the file does not exist) $ catalina_base/logs/Catalina. Out

Touch "$ catalina_base"/logs/Catalina. Out

# If the parameter is start-security, start Security Manager

If ["$1" = "-Security"]; then
Echo "using security manager"
Shift
"$ _ Runjava" $ java_opts $ catalina_opts/
-Djava. endorsed. dirs = "$ java_endorsed_dirs"-classpath "$ classpath "/
-Djava. Security. Manager/
-Djava. Security. Policy = "$ catalina_base"/CONF/Catalina. Policy/
-Dcatalina. base = "$ catalina_base "/
-Dcatalina. Home = "$ catalina_home "/
-Djava. Io. tmpdir = "$ catalina_tmpdir "/
Org. Apache. Catalina. startup. Bootstrap "$ @" Start/
> "$ Catalina_base"/logs/Catalina. out 2> & 1 &

If [! -Z "$ catalina_pid"]; then
Echo $! > $ Catalina_pid
Fi

# If the parameter is a standalone start, start Tomcat in the new window

Else
"$ _ Runjava" $ java_opts $ catalina_opts/
-Djava. endorsed. dirs = "$ java_endorsed_dirs"-classpath "$ classpath "/
-Dcatalina. base = "$ catalina_base "/
-Dcatalina. Home = "$ catalina_home "/
-Djava. Io. tmpdir = "$ catalina_tmpdir "/
Org. Apache. Catalina. startup. Bootstrap "$ @" Start/
> "$ Catalina_base"/logs/Catalina. out 2> & 1 &

If [! -Z "$ catalina_pid"]; then
Echo $! > $ Catalina_pid
Fi
Fi

# + ---------------------------------------------------- +
# | ...... When the Catalina. Sh parameter is stopped, ...... |
# | Shut down the Tomcat server !!! |
# + ---------------------------------------------------- +

Elif ["$1" = "stop"]; then
# Remove the stop Parameter

Shift
# The class for disabling Tomcat server is org. Apache. Catalina. startup. Bootstrap-> main ("stop ");
# Note: Java-D is used to set system attributes.

Exec "$ _ runjava" $ java_opts $ catalina_opts/
-Djava. endorsed. dirs = "$ java_endorsed_dirs"-classpath "$ classpath "/
-Dcatalina. base = "$ catalina_base "/
-Dcatalina. Home = "$ catalina_home "/
-Djava. Io. tmpdir = "$ catalina_tmpdir "/
Org. Apache. Catalina. startup. Bootstrap "$ @" Stop

# + ---------------------------------------------------- +
# | ...... When the execution of the Catalina. Sh parameter is unidentifiable ...... |
# | Print help information to view the meaning of various parameters !!! |
# + ---------------------------------------------------- +

Else
Echo "Usage: Catalina. Sh (commands ...)"
Echo "commands :"
Echo "Debug start Catalina in a debugger"
Echo "debug-security debug Catalina with a security manager"
Echo "embedded start Catalina in Embedded mode"
Echo "JPDA start Catalina under JPDA Debugger"
Echo "Run start Catalina in the current window"
Echo "Run-security start in the current window with security manager"
Echo "start Catalina in a separate window"
Echo "start-security start in a separate window with security manager"
Echo "Stop Catalina"
Exit 1
Fi
Tomcat sets remote debugging settings http://blog.chinaunix.net/u/21344/showart_498246.html in Tomcat/bin/Catalina. BAT file Add the following settings, of course set catalina_opts variable should be before using it. This is to set some virtual machine parameters during Tomcat startup so that the server can allow remote connection. Address = 5888 indicates the port number for remote connection and can be set to any other non-conflicting port. Other application servers, such as WebLogic, should be able to set these parameters. If you are interested, you can test them. Set catalina_opts =-server-xdebug-xnoagent-djava. compiler = none-xrunjdwp: Transport = dt_socket, Server = Y, suspend = N, address = 5888 and so on. Restart Tomcat and start it independently, instead of starting it in the plug-in of elasticsearch. Open the debug settings window in eclipse, select remote Java application, create a debug item, enter the Server IP address and the configured port number, and click OK to enter the debug status. However, in Linux, the Catalina. Sh file needs to be edited. And change it to catalina_opts = "-server-xdebug-xnoagent-djava. compiler = none-xrunjdwp: Transport = dt_socket, Server = Y, suspend = N, address = 5888 "is to remove the set, which is caused by double quotation marks. in Linux, there is no set syntax.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/cchaha/archive/2009/03/06/3962502.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.