計(jì)算機(jī)專業(yè)畢業(yè)外文翻譯--使用 eclipse 遠(yuǎn)程調(diào)試 java 應(yīng)用程序_第1頁
已閱讀1頁,還剩18頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、<p>  Debug Java applications remotely with Eclipse</p><p>  Use the power of the Eclipse IDE to spread around your Java application debugging</p><p>  Level: Intermediate</p><p&

2、gt;  Charles Lu (charleslu@tw.ibm.com), Software Engineer, IBM</p><p>  09 Dec 2008</p><p>  You don't need to debug Java? applications on just your local desktop. Learn how to spread around

3、 your debugging using different connection types that make up remote debugging. This article explains the features and examples that show how to set up remote application debugging.</p><p>  Remote debugging

4、 can be useful for application development, such as developing a program for a low-end machine that cannot host the development platform, or debugging programs on dedicated machines like Web servers, whose services canno

5、t be shut down. Other examples include Java applications running with limited memory or CPU power, such as mobile devices, or developers wanting to separate the application and development environments, etc.</p>&

6、lt;p>  Prerequisites</p><p>  If you don't have it already, download Eclipse V3.4 (Ganymede). In Ganymede, the socket listening connector has been added to the Remote Java Application launch-configura

7、tion type. Eclipse's new socket listening connector allows you to start the Java debugger, which listens for a connection on a specific socket. The program being debugged can then be started with command-line options

8、 to connect to the debugger. Prior to the Ganymede release, only a socket-attaching connector was provided, and th</p><p>  To use remote debugging, Java Virtual Machine (JVM) V5.0 or later must be used, suc

9、h as IBM® J9 or Sun Microsystems' Java SE Development Kit (JDK). In this article, we focus on remote debugging, rather than detail each of Eclipse's debugging features. See Resources for more information abo

10、ut debugging with Eclipse and where to find the aforementioned software.</p><p>  JPDA introduction</p><p>  Sun Microsystems' Java Platform Debugger Architecture (JPDA) technology is a mult

11、itiered architecture that allows you to debug Java applications in all situations easily. The JPDA consists of two interfaces (the JVM Tool Interface and JDI, respectively), a protocol (Java Debug Wire Protocol), and two

12、 software components that tie them together (back-end and front-end). It's designed for use by debuggers in any environment. JPDA is not only for desktop systems but works well with embedded systems,</p><p

13、>  The JVM Tool Interface (JVMTI) defines that a VM must provide for debugging. (Editor's note: Starting with Java V5, JVMTI replaced JVMDI, which was used in Java V1.4.) The Java Debug Wire Protocol (JDWP) descri

14、bes the format of debugging information and requests transferred between the process being debugged and a debugger front end, which implements the JDI, such as Eclipse, Borland JBuilder, and many others. The program bein

15、g debugged is often called the debuggee in Sun's JPDA specification. T</p><p>  Listing 1. The Java Platform Debugger Architecture</p><p>  Therefore, any third-party tools and VM based on J

16、PDA should work together without complaint. This client-server architecture allows you to debug a Java program from a local workstation running the platform, or even debug it from a remote computer on your network.</p

17、><p>  Before talking about the debug-scenario stuff, we need to introduce two terms used in the JPDA specification: connector and transport. A connector is a JDI abstraction used to establish a connection betw

18、een a debugger application and a target VM. A transport defines how applications access and transmit data between the front end and back end. The connectors "map" to the available transport types and the modes

19、of connection. In Sun's reference implementation of JPDA, two transport mechanisms are </p><p>  Socket-attaching connector </p><p>  Shared-memory attaching connector </p><p> 

20、 Socket-listening connector </p><p>  Shared-memory listening connector </p><p>  Command-line launching connector </p><p>  In establishing a connection between a debugger applicat

21、ion and target VM, one side acts as a server and listens for a connection. At some later time, the other side attaches to the listener and establishes a connection. The connections allow the debugger application or the t

22、arget VM to act as a server. The communications among processes can be running on one machine or different machines.</p><p>  The problem with debugging a Java program remotely is not in the debugger front e

23、nd but the remote Java back end. Unfortunately, there is not much information about this in the Eclipse help system. In fact, JDI and JVMTI are implemented by Eclipse and the Java runtime environment, respectively. The o

24、nly thing we are concerned with is the JDWP, which contains the information to communicate with the JVMTI and JDI. The JDWP contains many arguments that have been added to invoke the application for </p><p>

25、<b>  -Xdebug </b></p><p>  Enables debugging features.</p><p>  -Xrunjdwp:<sub-options> </p><p>  Loads the implementation of JDWP in the target VM. It uses a tran

26、sport and the JDWP protocol to communicate with a separate debugger application. Specific suboptions are described below.</p><p>  Starting from Java V5, you can use the -agentlib:jdwp option, instead of -Xd

27、ebug and -Xrunjdwp. But if you have to connect to the VM prior to V5, -Xdebug and -Xrunjdwp will be the only choice. Following are brief descriptions of the -Xrunjdwp suboptions.</p><p>  transport </p>

28、;<p>  Generally, socket transport is used. But shared-memory transport can also be used on the Windows platform, if available.</p><p><b>  server </b></p><p>  If the value i

29、s y, the target application listens for a debugger application to attach. Otherwise, it attaches to a debugger application at the specified address.</p><p><b>  address </b></p><p> 

30、 This is the transport address for the connection. If the server is n, attempt to attach to a debugger application at this address. Otherwise, listen for a connection at this port.</p><p><b>  suspend

31、</b></p><p>  If the value is y, the target VM will be suspended until the debugger application connects.</p><p>  For detailed explanations for each debug setting, refer to the JPDA docum

32、entation (see Resources).</p><p>  Listing 2 shows an example of how to launch a VM in debug mode and listen for a socket connection at port 8765.</p><p>  Listing 2. Target VM acts as a debug s

33、erver</p><p>  Listing 3 shows how to attach to a running debugger application using a socket on host 127.0.0.1 at port 8000.</p><p>  Listing 3. Target VM acts as a debug client</p><

34、p>  Remote debugging features in Eclipse</p><p>  Eclipse is a graphical Java debugger front end. The JDI is implemented in org.eclipse.jdt.debug bundle. In this article, we don't discuss the details

35、of JDI implementation. See Resources for information about Eclipse JDT and Java JDI technology.</p><p>  The first thing we want to know is which Eclipse connector to use. To learn the remote connection type

36、s provided by Eclipse, you can add a launch configuration in Remote Java Application by going to the Eclipse menu and selecting Run > Debug Configurations..., then selecting the connector from the dropdown list. Two c

37、onnectors are provided in Ganymede:</p><p>  Socket Attach </p><p>  Socket Listen </p><p>  For the socket-listening connector, the Eclipse VM will be the host to be connected by t

38、he remote Java application. For the socket-attaching connector, the target VM will be the host. There is no difference for application debugging between the two connectors — the user may choose. A good rule of thumb is t

39、o use the faster, more powerful computer as the VM debug host because of the computational resources required.</p><p>  Before debugging your Java application, you may need to make sure the debug options are

40、 all enabled for your remote application. If that information is not available, you will get an error message, such as "Debug information is not available" or "Unable to install breakpoint due to missing l

41、ine number." You can modify the settings from the Eclipse menu by changing what's set in Window > Preferences > Java > Compiler.</p><p>  Figure 1. Debug options in Eclipse</p><

42、p>  Debug an application remotely</p><p>  We are ready to start debugging an application remotely. Let's do it step by step:</p><p>  1. Create a Java project with a simple class </p&

43、gt;<p>  We create a simple class for debugging purpose. Listing 4 shows the sample code.</p><p>  Listing 4. Sample code for debugging</p><p>  2. Set a breakpoint </p><p> 

44、 Set a breakpoint in the code. In this example, we set the breakpoint in the line System.out.println("This is a test.");.</p><p>  Figure 2. Set breakpoints in Eclipse</p><p>  3. Deb

45、ug the application locally </p><p>  Before debugging your application, ensure that the debug options described in Figure 1 are enabled for the project. It's unnecessary to debug an application locally,

46、but we can make sure all the debug information is available. Right-click on the Java project, select Debug As and select Java Application (see Figure 3). If the application execution is stopped at the breakpoint, the deb

47、ugging information is presented correctly. You can continue to use the debugging features, such as displaying the </p><p>  Figure 3. Debug the application locally</p><p>  4. Export the Java p

48、roject </p><p>  We will use this application as the debug target. Right-click on the Java project, select Export, select Java, then choose JAR file or Runnable JAR file to export the project. The JAR file w

49、ill be generated at the desired location. Be aware that if the Java source does not match the target application, the debug function will not work correctly.</p><p>  5. Run the Java application manually <

50、;/p><p>  Open a console to launch the application manually to make sure the Java runtime environment is configured properly.</p><p>  Listing 5. Sample to invoke Java application</p><p&

51、gt;  6. Debug the application remotely </p><p>  Copy the JAR file to the appropriate location on the remote computer, or even the same machine, invoke the debug server, and then attach a client to it. The s

52、imple Java application can act as a debug server or client. Depending on the configuration, you can choose either Socket Attach or Socket Listen connection type in Eclipse. Learn how to run the application as a server or

53、 client in the following two sections.</p><p>  Target VM acts as debug server</p><p>  The following example invokes the Java application on the remote side, acts as a debug server, and listens

54、 for a socket connection on port 8000. The target VM will be suspended until the debugger connects.</p><p>  Listing 6. VM invocation sample for socket attaching mode in Eclipse</p><p>  Start E

55、clipse using the remote launch configuration and specify the target VM address of the remote application. To do this, click Run > Debug Configurations, and double-click the Remote Java Application in the Eclipse menu.

56、 From the newly created launch configuration, specify the IP and port for target application. To run the remote application in the same machine, simply specify the host IP as localhost or 127.0.0.1.Figure 4. Configurati

57、on of socket-attaching connection</p><p>  Select Allow termination of remote VM option to terminate the VM to which you are connecting during application debugging.</p><p>  Figure 5. Terminat

58、e button in Eclipse</p><p>  Target VM acts as debug client</p><p>  The second example is to use a simple Java application that acts as a debug client, and the debugger front end acts as a deb

59、ug server. Eclipse uses the socket listen-mode connection type for listening. The debug front end must be started in advance to listen on a specific port. Figure 6 shows a sample configuration to set up listening.Figure

60、 6. Configuration of socket-listening connection</p><p>  Click the Eclipse Debug button, and the status bar will show the message "waiting for vm to connect at port 8000..." When you see that, st

61、art the remote application. Listing 7 shows how to invoke the Java application as a debug client and attach it to a running debugger application using a socket on host 127.0.0.1 at port 8000.Listing 7. VM invocation sam

62、ple for socket-listening connection in Eclipse</p><p>  If everything goes well, the debug perspective will be displayed to support the application debugging, and the execution of the remote Java application

63、 will be stopped normally. This is similar to Step 3 that we did in local debugging (see Figure 3). At this point, you can use standard debugging functions, such as setting breakpoints and values, step execution, etc.<

64、;/p><p>  Conclusion</p><p>  This article illustrated how to use the Eclipse built-in remote Java application configuration type to perform application debugging remotely. It introduced how to set

65、 up a Java application to invoke remote debugging and helped you understand the connectors Eclipse provides. Finally, you learned how to apply this technology to your projects.</p><p><b>  Resources<

66、;/b></p><p><b>  Learn</b></p><p>  "Eclipse Ganymede at a glance" is an overview of several Ganymede projects, along with resources for more information.</p><

67、;p>  For an introduction to the debugging with the Eclipse platform, see "Debugging with the Eclipse Platform."</p><p>  Expand your Eclipse debugging knowledge by checking out Eclipse Debugging

68、 Resources.</p><p>  Learn more about Java Platform Debugger Architecture by Sun Microsystems.</p><p>  Read the Java Platform Debugger Architecture documentation to learn more about JPDA.</p

69、><p>  Read the Java Debug Interface documentation to learn more about JDI.</p><p>  The JDT project provides the tool plug-ins that implement a Java IDE supporting the development of any Java appl

70、ication, including Eclipse plug-ins.</p><p>  Check out the "Recommended Eclipse reading list." </p><p>  Browse all the Eclipse content on developerWorks.</p><p>  New to

71、 Eclipse? Read the developerWorks article "Get started with Eclipse Platform" to learn its origin and architecture, and how to extend Eclipse with plug-ins.</p><p>  Expand your Eclipse skills by c

72、hecking out IBM developerWorks' Eclipse project resources.</p><p>  To listen to interesting interviews and discussions for software developers, check out check out developerWorks podcasts.</p>&l

73、t;p>  Stay current with developerWorks' Technical events and webcasts.</p><p>  Watch and learn about IBM and open source technologies and product functions with the no-cost developerWorks On demand d

74、emos.</p><p>  Check out upcoming conferences, trade shows, webcasts, and other Events around the world that are of interest to IBM open source developers.</p><p>  Visit the developerWorks Open

75、 source zone for extensive how-to information, tools, and project updates to help you develop with open source technologies and use them with IBM's products.Get products and technologies</p><p>  The Ja

76、va 2 Standard Edition V5 or greater is available from Sun Microsystems.</p><p>  Check out the latest Eclipse technology downloads at IBM alphaWorks.</p><p>  Download Eclipse Platform and other

77、 projects from the Eclipse Foundation.</p><p>  Download IBM product evaluation versions, and get your hands on application development tools and middleware products from DB2®, Lotus®, Rational

78、4;, Tivoli®, and WebSphere®.</p><p>  Innovate your next open source development project with IBM trial software, available for download or on DVD.</p><p>  About the author</p>

79、<p>  Charles Lu is a software developer at the IBM China Software Development Lab and currently works on IBM Lotus Expeditor development. He is interested in device programming, instant messaging, and voice techno

80、logy.</p><p>  本文來自于:http://www.ibm.com/developerworks/java/library/os-eclipse-javadebug/index.html?S_TACT=105AGX02&S_CMP=EDU</p><p>  使用 Eclipse 遠(yuǎn)程調(diào)試 Java 應(yīng)用程序</p><p>  利用 Ecli

81、pse IDE 的強(qiáng)大功能遠(yuǎn)程調(diào)試 Java 應(yīng)用程序</p><p><b>  級別: 中級</b></p><p>  Charles Lu, 軟件工程師, IBM</p><p>  2009年12月9日</p><p>  在本地計(jì)算機(jī)上調(diào)試 Java? 應(yīng)用程序并不是惟一的選擇。學(xué)習(xí)如何使用構(gòu)成遠(yuǎn)程調(diào)試的不同

82、連接類型進(jìn)行遠(yuǎn)程調(diào)試。本文概述了設(shè)置遠(yuǎn)程應(yīng)用程序調(diào)試的特性和示例。</p><p>  遠(yuǎn)程調(diào)試對應(yīng)用程序開發(fā)十分有用。例如,為不能托管開發(fā)平臺的低端機(jī)器開發(fā)程序,或在專用的機(jī)器上(比如服務(wù)不能中斷的 Web 服務(wù)器)調(diào)試程序。其他情況包括:運(yùn)行在內(nèi)存小或 CUP 性能低的設(shè)備上的 Java 應(yīng)用程序(比如移動(dòng)設(shè)備),或者開發(fā)人員想要將應(yīng)用程序和開發(fā)環(huán)境分開,等等。</p><p><

83、;b>  先決條件</b></p><p>  如果您還沒安裝該程序,請下載 Eclipse V3.4(Ganymede)。在 Ganymede 中,套接字(socket)監(jiān)聽連接器被添加到 Remote Java Application 啟動(dòng)配置類型。Eclipse 最新的套接字監(jiān)聽連接器允許您打開 Java 調(diào)試器,它能夠監(jiān)聽特定套接字上的連接??梢詮拿钚羞x項(xiàng)打開被調(diào)試的程序,并將其連接到

84、調(diào)試器。在 Ganymede 發(fā)布之前,僅有一個(gè)連接套接字的連接器,被調(diào)試的程序所在的機(jī)器必須是一個(gè)與調(diào)試器相連的調(diào)試主機(jī)。由于受到內(nèi)存和 CPU 不足的限制,要想讓移動(dòng)設(shè)備充當(dāng)主機(jī)是不現(xiàn)實(shí)的。</p><p>  為了進(jìn)行遠(yuǎn)程調(diào)試,必須使用 Java Virtual Machine (JVM) V5.0 或更新版本,比如 IBM® J9 或 Sun Microsystem 的 Java SE Deve

85、lopment Kit(JDK)。本文主要討論遠(yuǎn)程調(diào)試,而不是每個(gè) Eclipse 調(diào)試特性的細(xì)節(jié)。查看 參考資料 獲得更多關(guān)于使用 Eclipse 進(jìn)行調(diào)試的信息,并且可以找到上面提到的軟件。</p><p><b>  JPDA 簡介</b></p><p>  Sun Microsystem 的 Java Platform Debugger Architectu

86、re (JPDA) 技術(shù)是一個(gè)多層架構(gòu),使您能夠在各種環(huán)境中輕松調(diào)試 Java 應(yīng)用程序。JPDA 由兩個(gè)接口(分別是 JVM Tool Interface 和 JDI)、一個(gè)協(xié)議(Java Debug Wire Protocol)和兩個(gè)用于合并它們的軟件組件(后端和前端)組成。它的設(shè)計(jì)目的是讓調(diào)試人員在任何環(huán)境中都可以進(jìn)行調(diào)試。JPDA 不僅能夠用于桌面系統(tǒng),而且能夠在嵌入式系統(tǒng)上很好地工作。</p><p>

87、  JVM Tool Interface (JVMTI) 規(guī)定必須為調(diào)試提供 VM(編輯注:從 Java V5 開始,將用 JVMTI 代替 Java V1.4 中的 JVMDI)。Java Debug Wire Protocol (JDWP) 描述調(diào)試信息的格式,以及在被調(diào)試的進(jìn)程和調(diào)試器前端之間傳輸?shù)恼埱?,調(diào)試器前端實(shí)現(xiàn) JDI,比如 Eclipse、Borland JBuilder 等。根據(jù) Sun 的 JPDA 規(guī)范,被調(diào)試的程

88、序常常稱為 debuggee。JDI 是一個(gè)高級的接口,它定義用于遠(yuǎn)程調(diào)試的信息和請求。下面給出了調(diào)試器的架構(gòu)。</p><p>  清單 1. Java 平臺調(diào)試器架構(gòu)</p><p>  因此,任何第三方工具和基于 JPDA 的 VM 應(yīng)該都能協(xié)調(diào)工作。通過這個(gè)客戶機(jī)-服務(wù)器架構(gòu),您可以從運(yùn)行該平臺的本地工作站調(diào)試 Java 程序,甚至還可以通過網(wǎng)絡(luò)進(jìn)行遠(yuǎn)程調(diào)試。</p>

89、<p>  在討論調(diào)試場景之前,我們先了解 JPDA 規(guī)范中的兩個(gè)術(shù)語:連接器和傳輸。連接器是一個(gè) JDI 抽象,用來在調(diào)試器應(yīng)用程序和目標(biāo) VM 之間建立連接。傳輸定義應(yīng)用程序如何進(jìn)行訪問,以及數(shù)據(jù)如何在前端和后端之間傳輸。連接器 “映射” 到可用的傳輸類型和連接模式。在 Sun 的 JPDA 參考實(shí)現(xiàn)中,為 Microsoft® Windows® 提供了兩個(gè)傳輸機(jī)制:套接字傳輸和共享內(nèi)存?zhèn)鬏???捎玫倪B

90、接器:</p><p><b>  連接套接字連接器 </b></p><p>  連接共享內(nèi)存連接器 </p><p><b>  監(jiān)聽套接字連接器 </b></p><p>  監(jiān)聽共享內(nèi)存連接器 </p><p><b>  啟動(dòng)命令行連接器 </b&g

91、t;</p><p>  在調(diào)試器應(yīng)用程序和目標(biāo) VM 之間建立連接時(shí),有一端將用作服務(wù)器并監(jiān)聽連接。隨后,另一端將連接到監(jiān)聽器并建立一個(gè)連接。通過連接,調(diào)試器應(yīng)用程序或目標(biāo) VM 都可以充當(dāng)服務(wù)器。進(jìn)程之間的通信可以在同一個(gè)機(jī)器或不同的機(jī)器上運(yùn)行。</p><p>  要遠(yuǎn)程調(diào)試 Java 程序,難點(diǎn)不是在調(diào)試器的前端,而是遠(yuǎn)程 Java 后端。不幸的是,Eclipse 幫助系統(tǒng)中為這方

92、面提供的信息并不多。事實(shí)上,JDI 和 JVMTI 是分別由 Eclipse 和 Java 運(yùn)行時(shí)環(huán)境實(shí)現(xiàn)的。我們僅需要考慮 JDMP,因?yàn)樗c JVMTI 和 JDI 進(jìn)行通信所需的信息。JDWP 包含許多參數(shù),用于為遠(yuǎn)程 Java 應(yīng)用程序調(diào)用所需的程序。以下是本文用到的一些參數(shù)。</p><p><b>  -Xdebug </b></p><p><

93、b>  啟用調(diào)試特性。</b></p><p>  -Xrunjdwp:<sub-options> </p><p>  在目標(biāo) VM 中加載 JDWP 實(shí)現(xiàn)。它通過傳輸和 JDWP 協(xié)議與獨(dú)立的調(diào)試器應(yīng)用程序通信。下面介紹一些特定的子選項(xiàng)。</p><p>  從 Java V5 開始,您可以使用 -agentlib:jdwp 選項(xiàng),

94、而不是 -Xdebug 和 -Xrunjdwp。但如果連接到 V5 以前的 VM,只能選擇 -Xdebug 和 -Xrunjdwp。下面簡單描述 -Xrunjdwp 子選項(xiàng)。</p><p>  transport </p><p>  這里通常使用套接字傳輸。但是在 Windows 平臺上也可以使用共享內(nèi)存?zhèn)鬏敗?lt;/p><p><b>  server

95、 </b></p><p>  如果值為 y,目標(biāo)應(yīng)用程序監(jiān)聽將要連接的調(diào)試器應(yīng)用程序。否則,它將連接到特定地址上的調(diào)試器應(yīng)用程序。</p><p><b>  address </b></p><p>  這是連接的傳輸?shù)刂?。如果服?wù)器為 n,將嘗試連接到該地址上的調(diào)試器應(yīng)用程序。否則,將在這個(gè)端口監(jiān)聽連接。</p>

96、<p><b>  suspend </b></p><p>  如果值為 y,目標(biāo) VM 將暫停,直到調(diào)試器應(yīng)用程序進(jìn)行連接。</p><p>  要獲得每個(gè)調(diào)試設(shè)置的詳細(xì)解釋,請參考 JPDA 文檔(參見 參考資料)。</p><p>  清單 2 是一個(gè)示例,顯示如何在調(diào)試模式下啟動(dòng) VM 并監(jiān)聽端口 8765 的套接字連接。

97、</p><p>  清單 2. 作為調(diào)試服務(wù)器的目標(biāo) VM</p><p>  清單 3 顯示如何使用位于 8000 端口的主機(jī) 127.0.0.1 上的套接字連接運(yùn)行中的調(diào)試器應(yīng)用程序。</p><p>  清單 3. 作為調(diào)試客戶機(jī)的目標(biāo) VM</p><p>  Eclipse 中的遠(yuǎn)程調(diào)試特性</p><p>

98、;  Eclipse 是一個(gè)圖形化 Java 調(diào)試器前端。JDI 在 org.eclipse.jdt.debug 包中實(shí)現(xiàn)。本文不詳細(xì)討論 JDI 實(shí)現(xiàn)。參見 參考資料 獲得關(guān)于 Eclipse JDT 和 Java JDI 技術(shù)的信息。</p><p>  我們首先應(yīng)該知道要使用哪個(gè) Eclipse 連接器。要了解 Eclipse 提供的遠(yuǎn)程連接類型,您可以轉(zhuǎn)到 Eclipse 菜單并選擇 Run > D

99、ebug Configurations...,在 Remote Java Application 中添加一個(gè)啟動(dòng)配置,然后從下拉列表中選擇連接器。在 Ganymede 中共有兩個(gè)連接器:</p><p>  Socket Attach </p><p>  Socket Listen </p><p>  對于監(jiān)聽套接字的連接器,Eclipse VM 將是與遠(yuǎn)程 J

100、ava 應(yīng)用程序連接的主機(jī)。對于連接套接字的連接器,目標(biāo) VM 將作為主機(jī)。這兩種連接器對應(yīng)用程序調(diào)試沒有影響,用戶可以任意選擇。但根據(jù)經(jīng)驗(yàn),需要使用速度更快、更強(qiáng)大的計(jì)算機(jī)作為 VM 調(diào)試主機(jī),因?yàn)樾枰?jì)算的資源很多。</p><p>  在調(diào)試 Java 應(yīng)用程序之前,需要確保已經(jīng)為遠(yuǎn)程應(yīng)用程序啟用所有調(diào)試選項(xiàng)。如果選項(xiàng)信息不可用,您將收到一個(gè)錯(cuò)誤信息,比如 “Debug information is not

101、 available” 或 “Unable to install breakpoint due to missing line number”。您可以通過更改 Eclipse 菜單上的 Window > Preferences > Java > Compiler 來修改設(shè)置。</p><p>  圖 1. Eclipse 中的調(diào)試選項(xiàng) </p><p><b>

102、;  遠(yuǎn)程調(diào)試應(yīng)用程序</b></p><p>  現(xiàn)在,我們已經(jīng)準(zhǔn)備好遠(yuǎn)程調(diào)試應(yīng)用程序。我們分步執(zhí)行:</p><p>  1. 使用簡單類創(chuàng)建一個(gè) Java 項(xiàng)目 </p><p>  我們?yōu)檎{(diào)試創(chuàng)建一個(gè)簡單類。清單 4 給出了示例代碼。</p><p>  清單 4. 調(diào)試示例代碼</p><p> 

103、 2. 設(shè)置一個(gè)斷點(diǎn) </p><p>  在代碼中設(shè)置一個(gè)斷點(diǎn)。在這個(gè)例子中,我們在 System.out.println("This is a test."); 這行中設(shè)置斷點(diǎn)。</p><p>  圖 2. 在 Eclipse 中設(shè)置斷點(diǎn)</p><p>  3. 從本地調(diào)試應(yīng)用程序 </p><p>  在調(diào)試應(yīng)

104、用程序之前,確保已經(jīng)為項(xiàng)目啟用圖 1 中描述的調(diào)試選項(xiàng)。從本地調(diào)試應(yīng)用程序是沒有必要的,但是這可以確保是否所有調(diào)試信息都可用。右鍵單擊 Java 項(xiàng)目,并選擇 Debug As,然后選擇 Java Application(參見圖 3)。如果應(yīng)用程序在斷點(diǎn)處停止執(zhí)行,則表明調(diào)試信息正確顯示。這時(shí),可以繼續(xù)使用這些調(diào)試特性,比如顯示調(diào)試堆棧、變量或斷點(diǎn)管理等等。</p><p>  圖 3. 從本地調(diào)試應(yīng)用程序&l

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論