Java Remote Debugging (Java application and Web application)

Source: Internet
Author: User

As described in the summary, the frequent need to deploy the program to the test machine at the time of the tune-up, it is inconvenient to debug. The previous practice is to print information in the program to track, but this method is very limited, because often can not be located in the problem at once, need to constantly modify the program to print the statement, constantly restart the application, which takes a lot of time and effort. Therefore, it is a good solution to use remote debugging. The following is a description of Java application and Web application two.

One, remote debugging of Java application

1. Prepare the server-side environment to be debugged

First, a small piece of code is prepared and called in the Main method, and I'm writing a code that doesn't make any sense, just to illustrate the need, as follows:

123456789101112131415161718192021222324252627 packagecom.zzq.test;/** * @author zhengzhq E-mail:[email protected] * @version 创建时间:2015-9-4 下午02:59:35 */publicclassRemoteDebug {    publicstaticvoidcheckName(String name) {        if ("name1".equals(name)) {            System.out.println("this is name1");        elseif("name2".equals(name)) {            System.out.println("this is name2");        else{            System.out.println("unknow name "+ name + "!!!");        }    }    publicstaticvoidmain(String[] args) {        if(args.length > 0) {            checkName(args[0]);        else{            checkName("unknow");        }    }}

If there are pass values in the run, the first value is passed as name to the method, which is a very simple code. Through the development tool export-runnable jar, the specified good execution of the main Class->finish,jar package generation is completed, I export this side as Debug.jar. At this point the command line executes Java-jar Debug.jar, which appears as:

When additional boot information is added to the Java-jar, the program will open the remote debugging mode and be in a blocked state as follows:

1 java -Xms700m -Xmx700m -Xdebug -server -Xrunjdwp:transport=dt_socket,server=y,address=12345-jar debug.jar name1

Where address is the specified port.

2. Specify the client-side environment for debugging

Debugging code because the local environment owns, so directly in the IDE right-click->debug as->debug configurations, pop up the following window, under Remote application can be configured to remotely debug the project:

After the configuration is complete, click Debug under the Pop-up window and the program will automatically connect to the server side of the Debug. If the server side does not start, it means that the port is not listening, will be reported connection refused, otherwise the program according to set breakpoints into execution.

Second, WEB application

Put the app into a war package in the Tomcat/webapps directory, then set up tomcat/conf/startup.sh, and add the following script in front

1 SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=12345

And then start the process, there will be a print line on the remote debugging monitoring:

Client configuration is consistent with Java application and can be debugged by running

Java Remote Debugging (Java application and Web application)

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.