Java remote debugging Jpda+tomcat under Linux

Source: Internet
Author: User

Project to the Linux server, the server environment or data may be different from our local, this time we may need a remote breakpoint to debug, to see the value of each variable in the request process. Here our application server uses the tomcat5.5.17

This time you need to know the concept of JPDA.

Simply summarize the following JPDA:

The Java Platform Debugger Architecture (Jpda:java Platform Debug architecture) consists of a Java Virtual machine backend and a debug platform front-end
1.Java virtual machines provide Java debugging capabilities
2. The debug platform requests services from the Java Virtual machine by debugging the interactive protocol to debug programs running in the virtual machine

Here our eclipse is the front desk of the commissioning. We need to combine the local debug platform with the project that the server is running on.

First step: Launch Tomcat JPDA support

The startup command for Tomcat by default is:./catalina.sh start but this command is not starting our JPDA this service

We need to start the JPDA service, but Tomcat provides an integrated command:./catalina.sh JPDA start, which launches the JPDA service for our server JVM. Tomcat default JPDA service port is 8000, this time we use the command to look at the Netstat-an, to see if Port 8000 is already started.

Step two: Debug the front of the breakpoint from the local establishment JPDA

1. Under the "Run" menu in Eclipse, select the "Debug ..." menu (some versions of Eclipse are debug configuration) and select the "Remote Java Application" menu in the menu to the left of the popup dialog box. Right click, select "New", this time pop up a need to fill in the parameters of the dialog box

2. In the box that pops up, define the project name, select the project to debug on the breakpoint, Connect type (default standard (Socket Attach)), define where our web project is placed (where is our remote virtual machine), Fill in his IP and provide the service port number, this version of Tomcat is 8000. Finally select the source tag, add the project's source code, I usually choose to add a Java project way

3, switch to debug mode, you can see the debug of the relevant options are active state. Add a breakpoint to the local source file, and then request a link to the service to see if our breakpoint is successfully debugged.

The above operation has been verified by me.

Many servers provide this remote debugging interface services, so do not confine to Tomcat available, the main difference is that each server provides a different start-up mode of the JPDA, the service port provided by different, here we tomcat5.5 provide the starting mode is catalia.sh JPDA Start this command line way, the port defaults to 8000. When you are developing, follow the instructions provided by the server for debugging.

Add a frequently-seen operation command:

1. View the current Tomcat process number

[Java] view plaincopy

  1. [Root@localhost bin]# ps-ef|grep Tomcat

  2. Root14857     1  6  the: Apts/0    xx:xx: */usr/java/jdk1.6. 0_22/bin/java-djava.util.logging.config.file=/usr/local/tomcat6/conf/logging.properties- djava.util.logging.manager=org.apache.juli.classloaderlogmanager-agentlib:jdwp=transport=dt_socket,address= 8000, server=y,suspend=n-djava.endorsed.dirs=/usr/local/tomcat6/endorsed-classpath/usr/local/tomcat6/bin/ bootstrap.jar-dcatalina.base=/usr/local/tomcat6-dcatalina.home=/usr/local/tomcat6-djava.io.tmpdir=/usr/local/ Tomcat6/temp org.apache.catalina.startup.Bootstrap Start

  3. Root15055 14811  0  the: topts/0    xx:xx:xxgrep Tomcat

After executing the command above, you can see that the Tomcat process number is 14857.

2. Kill the current Tomcat process

[C-sharp] View plaincopy

    1. [Email protected] bin]# kill-9 14857

Why is this killing process? Because killing the Tomcat process with a regular shutdown.sh is slow, and occasionally because the resource usage is not closed, simply do this process
3, start the remote debugging JPDA

[Java] view plaincopy

    1. [root @localhost [root  bin]#  ./catalina.sh jpda start  

4. See if the default 8000 external service ports are started

[Java] view plaincopy

  1. [Root@localhost bin]# netstat-an|grep 8000   

  2. Tcp0      0 192.168.119.149:8000        192.168.70.80:1535established

5. How close is the test completed?

Kill the Tomcat process directly, or close tomcat as you normally would.

6, directly according to the above method for remote connection debugging. Add breakpoints in the local source code and view the remote server. Note that this 8000 port does not affect any of the original services. Just don't start our tomcat this way when we put the project on the line.


Java remote debugging Jpda+tomcat under Linux

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.