Set remote debugging settings in Tomcat

Source: Internet
Author: User
Tags stop script

 

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 (to) Tomcat STARTUP script Catalina. shhttp: // 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        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             Start Catalina in a separate window"  echo "  start -security   Start in a separate window with security manager"  echo "  stop              Stop Catalina"

 

2-script analysis

#! /Bin/sh #=============================================== ====================================## this script sets the correct environment variables and system information, start or stop Tomcat server # the specific operation is: # 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 Variabl E 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 to # 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) direc Using path location of temporary directory # The JVM shocould use (Java. io. tmpdir ). defaults to # $ 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_soc Ket ". # 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 the # 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 = falsecase "'uname'" incygwin *) cygwin = true; esac # PRG is the name of the executed script, which 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" fidone # prgdir is the PRG directory path name prgdir = 'dirname "$ PRG "' # Run $ catalina_home/bin/setenv. sh to set the environment variable # [-r filename] is to determine whether the file exists and read 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: Execute the script setclasspath. sh complete # Note: The Script setclasspath. sh changed the original $ classpath variable and set it to: # classpath = $ catalina_home/bin/Bootstrap. jar: $ java_home/lib/tools. jar # Bootstrap. jar is package Org. apache. catalina. startup package file, # contains the startup method Org. apache. catalina. startup. bootstrap. main (string [] ARGs) # tools. jar contains the javac compiler, which is used to compile the JSP file into servlet classif [-R "$ catalina_home"/bin/setclasspath. sh]; Then basedir = "$ catalina_home ". "$ catalina_home"/bin/setclasspath. shelse echo "cannot find $ catalina_home/bin/setclasspath. sh "Echo" this file is needed to run this program "Exit 1fi # add some jar files after the classpath environment variable # [-N string] to determine whether the string length is not 0; [-Z string] determines 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_ho Me "/lib/JSSE. jarficlasspath = "$ classpath": "$ catalina_home"/bin/Bootstrap. jar # specify the catalina_base variable # If catalina_base has no value, make catalina_base = $ catalina_homeif [-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/tempif [-z "$ catalina_tmpdir"] then # define the java. io. tmpdir to use for Catalina catalina_tmpdir = "$ catali Na_base "/tempfi # For cygwin, convert the path name to Windows format before running 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" 'f I # display information, and then run 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 Catalina. when the 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_op TS = "-xdebug-xrunjdwp: Transport = $ jpda_transport, address = $ jpda_address, Server = Y, suspend = N "fi catalina_opts =" $ catalina_opts $ jpda_opts "shiftfi #...... when Catalina. when the 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_en Dorsed_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 Catalina. when the sh parameter 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 Catalina. when the sh parameter is run ...... | # | start the Tomcat server in the current window !!! | # + -------------------------------------------------- + Elif ["$1" = "run"]; then # Remove the parameter run 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/CA Talina. 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 alone, start the Tomcat server in this window # The method to start in this window is to use exec, let the current process 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. dir S = "$ 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 Catalina. when the sh parameter is 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"-clas Spath "$ 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 else "$ _ runjava" $ java_opts $ catalina_opts/-djava in the new window. 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 # + ------------------------------------------------------ + # | ...... when Catalina. when the sh parameter is stop ...... | # | disable the Tomcat server !!! | # + -------------------------------------------------- + Elif ["$1" = "stop"]; then # Remove the parameter stop shift # the class for disabling the Tomcat server is Org. apache. catalina. startup. bootstrap-> main ("stop"); # Note: Java-D sets the system attribute 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 = "$ ca Talina_tmpdir "/org. apache. catalina. startup. bootstrap "$ @" stop # + ---------------------------------------------------- + # | ...... when Catalina. when sh parameters are unidentifiable ...... | # | print the 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 1fi
 
Set remote debugging settings in Tomcat
http://blog.chinaunix.net/u/21344/showart_498246.html
 
Add the following settings to the Catalina. BAT file of Tomcat/bin/. 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
In this way, you can restart Tomcat and start it independently without 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 this:

Catalina_opts = "-server-xdebug-xnoagent-djava. compiler = none-xrunjdwp: Transport = dt_socket, Server = Y, suspend = N, address = 5888"

That is to say, remove the set with double quotation marks, because in Linux, the set syntax does not exist.

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.