Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Java Debugger

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "how to implement the Java debugger". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to implement the Java debugger.

What is JDB?

Although there are some good debugging tools, the Java debugger (JDB) provides some advantages. The most important thing is that JDB is freely available and platform independent. The disadvantage is that it only has a command-line format, which some developers think is primitive and difficult to use. Some IDE have built the GUI interface to JDB debug API (such as Jikes). JDB is part of the JDK installation. It has been enhanced in the Java 2 platform. For more information, refer to the section on Java debugging API.

Details of JDB

You can configure JDB for debugging multiple projects. JDB will look for the jdb.ini configuration file in the user.home directory. Therefore, for each project, you should set the user.home property to point to another .ini file in another directory. You can do this by entering the following command:

Jdb-JmurdUser.homeowners. / / Will look in the current directory for the

/ / jdb.ini file

The jdb.ini file starts a JDB session, passing parameters and information about the system. The following is an example of a jdb.ini file. It includes the Java platform source code in the source path list and passes parameter 34 to the program. Then it runs and stops on line 2, showing the available memory and waiting for further input.

Load MyTest

Stop at MyTest:20

Use CJV hand java com JDK hand src

Run MyTest 34

Memory

You can record debugging sessions with JDB. Enable logging by creating the file .agentLog in the directory where JDB is running. In the .agentLog file, on the first line, put the file name to which you want to write the session information. When you run the jdb command, you will see jdb session information. The log file may contain the following:

-debug agent message log-

[debug agent: adding Debugger agent to system thread list]

[debug agent: adding Breakpoint handler to system thread list]

[debug agent: no such class: MyApplication.main]

Debugging Servlet with JDB and Servletrunner in the next chapter, we will complete an exercise to debug Servlet using the JDB and Servlet engines. Tomcat is a JSP/Servlet engine that docks well with JDB. Other Servlet engines that are Windows application .exe files cannot be run in debug mode. However, Tomcat has a startup script that allows you to configure it for debugging. The TOMCAT_OPTS environment variable needs to be configured. Running the engine in debug mode also affects CLASSPATH. Set the boot classpath with-Xbootclasspath and the path to the rt.jar and tools.jar files found in JDK 2.0. Alternatively, you can use Servletrunner for debugging. Servletrunner is an application that ships with JSDK. It allows you to run Servlet without using a Web browser. Servletrunner runs like a Java Web server, but lighter than a Java Web server. It handles HTTP requests for Servlet. Servletrunner runs the java sun.servlet.http.HttpServer command. You should use the HttpServer () class to run the jdb session.

When debugging Servlet, keep in mind that the Java Web server and Servletrunner do not mount and unmount Servlet by including the Servlet directory in the CLASSPATH. In fact, they use custom class loaders instead of the default system class loaders.

At this point, I believe you have a deeper understanding of "how to implement the Java debugger". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report