Eclipse QuickStart: Remote Debugging Java Application __java

Source: Internet
Author: User

"IT168 Technology" in software development, debugging is an indispensable link, it can help developers improve efficiency, save development time. In my opinion, local debugging is the best choice, and normally, when local debugging is not possible, we will consider remote debugging.

Some projects are running on the Linux operating system, and most of our projects are developed on the Windows platform. Especially in investment banking, many electronic trading programs run on Linux servers, which makes the development process cumbersome because we can't run the code in a local development environment.

Sometimes, whether for development or debugging, we can let the project run on the Windows platform, but sometimes, some uncontrollable factors, such as your project need to provide a platform for the development library, or need some Linux modules, Windows platform can not meet these requirements, Or your project is too large to run successfully on the Windows platform, because the project relies too much on systems to create the same running environment on the Windows Development platform.

In this case, my solution is to test the project with the help of a mock object. Of course, sometimes running application modules by thread alone is not necessarily the best solution, especially if you need to look up some child issues in a run-time environment by debugging a project, and these methods are less practical.

Eclipse provides us with the most useful features, called Remote debugging. With remote debugging, you can debug Linux on the Windows platform, and in order to improve development efficiency, it is important to understand how to install remote debugging and how to implement remote debugging in Eclipse.

  How to install remote debugging in Eclipse

1 installing Java projects in eclipse

2 Select the item and select "Debug Configurations" under the "Run" menu option

 Remote Debugging with Eclipse 1

3 The Debug Configuration window will pop up, select the "Remote Java Application" icon on the left, and select "New" on the right.

Eclipse Remote Debugging 2

 

4 after clicking "New", Eclipse will create a remote Java application configuration for the project you selected. The next step is to install the host and port for remote debugging.

  Remote Debugging in Eclipse 3

5 Enter the hostname and port now, and if you want to shut down the Java application running on the Linux platform from Eclipse, select the Allow termination of remote VM check box.

6 before debugging, make sure that all debugging information for the Java process is set up, while ensuring that the Java process is listening on the same host and port or eclipse does not establish a connection properly.

7 Click "Debug" to start debugging the host and port.

8 You can also select your item under the " Debug Configurations" menu in "Remote Java Application" and click "Debug".

  to debug a Java application remotely, make sure that the JVM has debugging options as follows:

Java-xdebug-xrunjdwp:transport=dt_socket,address=8001,server=y Suspend=y-jar StockTradingGUI.jar

With the Java Debug Wire Protocol (JDWP) Protocol, we can get Java application Stocktradinggui into debug mode with a listening port of 8001. suspend=y , when Eclipse connects the application to the specified debug port, the application begins to run.

It is important to run the application first and then connect to it, or eclipse will throw an exception "Failed to connect to remote VM." Connection refused ".

  hint One: in the JVM debug parameter, there is a parameter called "suspend", which has two values, "Y" or "n", and if you want to debug at first, set the parameter to "Suspend=y", So eclipse will connect to the Java application remotely.

If you want to run the project first and then connect to eclipse, you can set the parameter to "Suspend=n" so that the Java application will run correctly, and then eclipse will start the remote connection.

  Tip Two: Use the startup script to enter JVM debugging parameters, use variable isdebugenabled or remote_debug_port in the script, and export this variable when you want to remotely debug a Java application. The whole operation is very simple, only need a one-time installation.

  Tip Three: If you get the wrong hint "Failed to connect to remote VM." Connection refused "or" Connection refused:connect ", there are two possible causes. The first is that your Java project is not running on the remote host, the second is the input port and host name is incorrect, after the successful verification, you can fill in the full hostname.

  Tip Four : You also want to make sure that local eclipse and remote eclipse are running the same code base. using the Debug option "-G" to compile code, eclipse can easily gather debugging information, such as debugging information for local variables, by default, the class file may be larger by using the Debug option "-G", because it may contain some debugging information.

Related Article

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.