使用Eclipse以及JDB调试Java程序
学会使用Eclipse进行Java程序开发

学会使用Eclipse进行Java程序开发第一章:介绍Eclipse开发环境Eclipse是一种基于Java的可扩展开发平台,被广泛用于Java程序的开发。
它提供了一个强大的集成开发环境(IDE),使得程序员能够更加高效地进行Java程序的编写、调试和测试。
1.1 安装和配置Eclipse首先,我们需要从Eclipse官方网站下载适用于Java开发的版本。
安装完成后,打开Eclipse并选择所需的工作区位置。
接下来,我们需要配置Java Development Kit(JDK)的路径,以便Eclipse能够正常运行。
找到Eclipse菜单中的Preferences,然后选择Java -> Installed JREs,并添加JDK的路径。
1.2 了解Eclipse的界面Eclipse的主要界面由多个视图组成,包括编辑器、项目资源管理器、进度和控制台窗口等。
编辑器窗口用于编写和查看代码,而项目资源管理器窗口用于管理项目文件和文件夹。
通过自定义视图布局,我们可以根据自己的喜好来组织界面。
第二章:创建和管理Java项目在Eclipse中创建Java项目非常简单,只需按照以下步骤操作:2.1 创建新项目选择菜单中的File -> New -> Java Project。
在弹出的对话框中,输入项目名称并选择所需的JRE版本。
点击完成,即可创建一个空的Java项目。
2.2 导入现有项目如果已经有一个现有的Java项目,我们可以将其导入到Eclipse中。
选择菜单中的File -> Import -> General -> Existing Projects into Workspace,选择所需的项目文件夹,并点击完成。
2.3 添加源文件和库文件在项目资源管理器中,右键点击src文件夹,选择New -> Class,填写类的名称,并点击完成。
可以在编辑器中编写Java代码。
java调试程序的方法

java调试程序的方法Java调试程序是开发过程中非常重要的技能,它帮助您找出代码中的错误和问题,并对其进行修复。
本文将介绍Java调试程序的一些常用方法,包括使用IDE调试工具、使用日志调试、使用断点调试以及使用异常处理。
一、使用IDE调试工具IDE(集成开发环境)是一种强大的工具,在Java开发中常用的IDE有Eclipse、IntelliJ IDEA和NetBeans等。
IDE提供了许多高级调试工具,使得调试过程更加简单和高效。
1.断点调试:在代码中设置断点,当代码执行到断点处时,程序将停止执行,您可以逐行查看代码的执行过程,并观察变量的值。
通过断点调试,您可以快速找到代码中的问题。
2.监视变量:在IDE中,您可以选择监视变量,当程序执行到一些位置时,IDE会显示该变量的值。
通过观察变量的值,您可以找到与预期不符的情况。
3.查看堆栈信息:在程序运行过程中,如果发生异常,IDE会显示堆栈信息,其中包含了执行过程中的方法调用链。
通过查看堆栈信息,您可以追踪异常发生的位置,并找出造成异常的原因。
4.单步调试:在IDE中,您可以选择逐行执行代码,通过单步调试,您可以对代码的执行过程进行详细的观察,以检查代码是否按照预期执行。
二、使用日志调试日志是程序运行过程中生成的信息记录,通过在代码中添加日志语句,可以帮助您追踪代码执行过程,找到问题所在。
1.日志级别:日志通常有不同的级别,如DEBUG、INFO、WARN和ERROR等。
在调试时,可以将日志级别设置为DEBUG,这样可以显示更详细的信息,帮助您找到问题。
2. 日志输出:在Java中,常用的日志库有Log4j和Logback等。
通过配置日志输出方式,您可以将日志信息打印到控制台、日志文件或其他目标,方便对问题进行分析。
3. 日志分析工具:有许多日志分析工具可以帮助您分析和查找日志信息。
例如,使用ELK Stack(Elasticsearch, Logstash, Kibana)可以将日志信息集中存储,并提供、过滤和可视化功能。
使用Eclipse调试Java程序代码

使用Eclipse调试Java程序代码创建Java项目当Eclipse首次启动时进入的是资源透视图,在这个透视图中可以管理项目、文件夹、文件和其它资源,按照Eclipse的说法,这些面板叫做视图,一套完整的视图叫做透视图,在资源透视图中,你可以使用左上方的视图(导航视图)导航和创建资源。
在Eclipse中做事之前,如创建Java程序,需创建一个Java项目,创建Java项目的步骤如下:1、在导航视图上点击右键,在弹出的上下文菜单中选择新建项目;2、在新建项目对话框中,Eclipse提供了项目选项:Java,插件开发等。
因此你想要创建一个Java项目,在对话框左边选择Java;3、在对话框右边选择Java项目,如果你还安装了其它Java插件开发包,在这里也会一起列出来(如EJB,Servlet等),Eclipse默认安装的JDT仅支持标准Java应用程序,因此你必须选择Java项目选项;4、点击下一步进入新建项目向导对话框;5、首先给项目命一个名字,因为是一个简单的“Hello, world”例子,因此这里我输入“Hello”,点击下一步,设置构建Java项目的设置选项,对于这个项目你不需要做任何修改即可;6、点击完成;7、Eclipse此时会提示你这种项目是和Java透视图关联的,并询问你是否切换到Java透视图,选择是。
创建Java类当你创建好Java项目后就可以开始创建Java程序了,尽管不是非得这么做,但这样可以将你的Java类组织到包中,这是一次很好的实践,通常使用域名做为包名,这样可以减少名字冲突的可能性,如果你没有注册域名,也可以使用任何方便的,唯一的hoc名,我在这里使用 org.eclipseguide,项目名是hello,因此包的全名就是org.eclipseguide.hello。
按照下列步骤创建Java程序:1、在项目上点击右键,选择New.Class弹出新建Java类向导;2、第一个字段区域“源文件夹”默认是项目的文件夹,保持默认值;3、在包字段区域输入org.eclipseguide.hello;4、在类名字段区域输入HelloWorld;5、在“Which Method Stubs Would You Like to Create?”区域下,选中public static void main(String[] args),新建Java类的对话框如图1所示。
使用Eclipse进行Java应用程序开发的入门教程

使用Eclipse进行Java应用程序开发的入门教程第一章:介绍Eclipse和Java开发环境Eclipse是一款流行的集成开发环境(IDE),可用于开发各种编程语言,包括Java。
它提供了强大的工具和功能,使Java开发变得更加高效和便捷。
1.1 Eclipse的安装首先,下载适用于Java开发的Eclipse版本。
安装过程相对简单,按照向导提示顺序执行即可完成。
确保选择Java开发工具(Java Development Tools,JDT)的安装。
1.2 JDK的安装和配置Eclipse需要Java Development Kit(JDK)才能编译和运行Java 代码。
确保已安装最新版本的JDK,并将其配置为Eclipse的默认JDK。
1.3 创建Java项目启动Eclipse后,选择"File -> New -> Java Project"来创建一个新的Java项目。
在弹出的对话框中,输入项目名称并选择所需的JDK版本。
点击"Finish"来创建项目。
第二章:Eclipse的基本功能和工作空间2.1 工作空间Eclipse使用工作空间(Workspace)来组织项目和资源文件。
在启动Eclipse时,会要求选择工作空间文件夹。
一个工作空间可以包含多个项目。
2.2 项目资源Eclipse的"Package Explorer"窗口显示项目中的所有文件和文件夹。
你可以在此窗口中创建、删除和管理项目资源。
2.3 编辑器Eclipse的编辑器是主要的编码区域,用于编写和编辑Java代码。
当你双击项目中的Java文件时,它会在编辑器中打开。
2.4 调试器Eclipse提供强大的调试功能,可帮助你发现和修复代码中的错误。
你可以设置断点、单步执行代码、查看变量的值等。
调试器是开发过程中非常有用的工具。
第三章:Java项目的创建和配置3.1 创建包和类在Eclipse的"Package Explorer"窗口中,右键点击项目,选择"New -> Package"来创建一个包。
如何在Eclipse和MyEclipse开发工具中创建和调试基于JDBC的应用程序

如何在Eclipse和MyEclipse开发工具中创建和调试基于JDBC的应用程序1.1.1在当前的工作空间中再新建一个Java 工程项目1、工程项目的名称设置为JdbcApp2、在该project中添加一个类(1)启动程序类创建向导(2)设置类名称为JdbcAppMain,程序包名称为examples3、编程该类中的功能实现方法package examples;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class JdbcAppMain extends JFrame implements WindowListener{String[] columnNames = {};Object [][]dataRows;String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=pubs";String DBDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";Connection con=null;Statement stmt=null;PreparedStatement pstmt=null;ResultSet rs=null;ResultSetMetaData metaData;public JdbcAppMain(String windowTitle){super(windowTitle);int FrameWidth=600,FrameHeight=400;this.setSize(FrameWidth,FrameHeight);this.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width-FrameWidth)/2, (Toolkit.getDefaultToolkit().getScreenSize().height-FrameHeight)/2);this.addWindowListener(this);JPanel contentPanel=new JPanel();contentPanel.setLayout(new BorderLayout());this.setContentPane(contentPanel);try{Class.forName(DBDriver);}catch(ClassNotFoundException e){System.out.println("不能正确地加载驱动程序");}try{con=DriverManager.getConnection(url,"sa","1234");}catch(SQLException e){System.out.println("用户的口令不正确");}try{/*访问SQLServer2000中内置的pubs数据库中的“authors”表*/stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY ); //step 3rs=stmt.executeQuery("select * from authors");metaData=rs.getMetaData();int numberOfColumns = metaData.getColumnCount();columnNames = new String[numberOfColumns];for(int column = 0; column < numberOfColumns; column++){columnNames[column] = metaData.getColumnLabel(column+1);}//以下为获得记录集中的行数,因为此时的记录指针在第一行之前int rowCounter=0;if(st()){rowCounter=rs.getRow();}rs.beforeFirst(); //将记录指针回退到最开始处,此时必须将Cursor设置为可回滚 dataRows=new Object[rowCounter][numberOfColumns];int loopRowCounter=0;while(rs.next()){for(int column = 0; column < numberOfColumns; column++){dataRows[loopRowCounter][column]=rs.getObject(column+1);}loopRowCounter++;}rs.close();}catch(SQLException e){System.out.println("SQLState:"+e.getSQLState());System.out.println("Messager:"+e.getMessage());System.out.println("Vendor:"+e.getErrorCode());}JTable table=new JTable(dataRows,columnNames);JScrollPane jsp=new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);contentPanel.add(jsp,BorderLayout.CENTER);}public static void main(String args[]){JdbcAppMain mainframe=new JdbcAppMain("利用JDBC SQLServer2000的驱动程序连接SQLServer2000数据库");mainframe.show();}public void windowOpened(WindowEvent parm1) {}public void windowClosing(WindowEvent parm1){try{con.close();}catch(SQLException e){}this.dispose();System.exit(0);}public void windowClosed(WindowEvent parm1) {}public void windowIconified(WindowEvent parm1) {}public void windowDeiconified(WindowEvent parm1) {}public void windowActivated(WindowEvent parm1) {}public void windowDeactivated(WindowEvent parm1) {}}4、在项目中添加支持MS SQLServer数据库系统的JDBC驱动程序到本项目中(1)选择所要添加的JDBC驱动程序文件(2)点击“添加外部Jar”按钮,最后为下面的状态5、查看某个类的定义比如,我们希望查看Frame类的定义,则可以选中该Frame类,然后选择“浏览”菜单中的相应的项目。
eclipse平台介绍及怎样使用Eclipse平台调试您的软件项目

怎样使用Eclipse平台调试您的软件项目发布时间:2005.05.12 11:15来源:IBM DW作者:Paul Leszek调试是程序员无法回避的工作。
调试方法有许多种,但归根结底,就是找到引发错误的代码。
举例来说,在 Linux 应用程序中,分段故障被认为是最常见的错误之一。
当程序尝试访问未分配给它的内存并因为分段违例而终止时,将产生这种错误。
要修正这种错误,您需要找到引发该行为的那行代码。
一旦找到有问题的代码行,这对于知道引发错误的上下文及其相关的值、变量和方法也是有所帮助的。
使用调试器将使查找这些信息变得相当简单。
Eclipse 调试器及 Debug 视图Eclipse 平台的特色在于内置了 Java 调试器,该调试器提供所有标准调试功能,包括进行单步执行、设置断点和值、检查变量和值以及暂挂和恢复线程的能力。
此外,您还可以调试在远程机器上运行的应用程序。
Eclipse 平台主要是一个 Java 开发环境,但其体系结构同时也向其它编程语言开放。
如以下您将看到的,同一个 Eclipse 的 Debug 视图也可用于 C 和 C++ 编程语言。
Eclipse 平台工作台(Eclipse Platform Workbench)及其工具是基于 Java 开发工具(JDT)组件所构建的。
这些组件向 Eclipse 提供以下功能:1、项目管理工具2、透视图和视图3、构建器、编辑器、搜索和构建功能4、调试器Eclipse 调试器本身是作为 Eclipse 二进制文件中包含的标准插件而存在的。
Eclipse 还有一个特别的 Debug 视图,允许您在工作台中管理程序的调试和运行。
它为调试中的每个目标显示其暂挂线程的堆栈帧。
程序中的各个线程以作为树的节点出现,而 Debug 视图则显示运行中的各目标的进程。
如果暂挂一个线程,则其堆栈帧显示为子元素。
在您开始使用 Eclipse 调试器之前,假定您已经安装了适当的 Java SDK/JRE(我推荐您使用 Java VM 1.4)和 Eclipse 平台 SDK 2.0/2.1,且两者都工作正常。
使用Eclipse进行Java程序开发

使用Eclipse进行Java程序开发1. 简介1.1 Eclipse的历史和特点1.2 Eclipse与Java程序开发的关系Eclipse是一款开源的集成开发环境(Integrated Development Environment,IDE),最初由IBM公司于2001年发布。
它是基于Java语言开发的,与Java程序开发紧密相关。
Eclipse提供了许多功能和工具,使Java程序员能够高效地开发、调试和管理Java应用程序。
2. 下载和安装Eclipse2.1 访问Eclipse官网2.2 选择适合的版本2.3 下载和安装Eclipse2.4 配置Java Development Kit(JDK)要开始使用Eclipse进行Java程序开发,首先需要下载Eclipse 并将其安装在本地计算机上。
可以通过访问Eclipse官网来获得最新版本的Eclipse。
根据操作系统的不同,选择适当的版本进行下载和安装。
同时还需要配置Java Development Kit(JDK),以便Eclipse能够正确地编译和运行Java代码。
3. 创建Java项目3.1 打开Eclipse3.2 创建新项目3.3 配置项目设置在Eclipse中创建一个新的Java项目是非常简单的。
只需打开Eclipse IDE,然后选择“File”菜单中的“New”选项,再选择“Java Project”。
在弹出的窗口中,输入项目名称并选择目标JDK版本,然后点击“Finish”按钮即可创建一个新的Java项目。
在创建项目后,可以根据需要配置项目的设置,如编译选项、构建路径等。
4. 编写Java代码4.1 创建Java类4.2 编辑Java代码4.3 代码自动补全和快捷键4.4 调试Java程序在Eclipse中,可以轻松地编写Java代码。
只需在项目资源管理器中右键单击项目名称,然后选择“New”和“Class”。
在弹出的窗口中,输入类名并选择所需的选项,然后点击“Finish”按钮即可创建一个新的Java类。
在Eclipse中使用debug(Eclipse调试常用技巧)

Eclipse调试常用技巧1、条件断点断点大家都比较熟悉,在Eclipse Java编辑区的行头双击就会得到一个断点,代码会运行到此处时停止。
条件断点,顾名思义就是一个有一定条件的断点,只有满足了用户设置的条件,代码才会在运行到断点处时停止。
在断点处点击鼠标右键,选择最后一个"Breakpoint Properties"断点的属性界面及各个选项的意思如下图,2、变量断点断点不仅能打在语句上,变量也可以接受断点,上图就是一个变量的打的断点,在变量的值初始化,或是变量值改变时可以停止,当然变量断点上也是可以加条件的,和上面的介绍的条件断点的设置是一样的。
3、方法断点方法断点就是将断点打在方法的入口处,方法断点的特别之处在于它可以打在JDK的源码里,由于JDK在编译时去掉了调试信息,所以普通断点是不能打到里面的,但是方法断点却可以,可以通过这种方法查看方法的调用栈。
4、改变变量值代码停在了断点处,但是传过来的值不正确,如何修改一下变量值保证代码继续走正确的流程,或是说有一个异常分支老是进不去,能不能调试时改一下条件,看一下异常分支代码是否正确?在Debug视图的Variables小窗口中,我们可以看到mDestJarName变量的值为"F:\Study\eclipsepro\JarDir\jarHelp.jar"我们可以在变量上右键,选择"Change Value..."在弹出的对话框中修改变量的值,或是在下面的值查看窗口中修改,保用Ctr+S保存后,变量值就会变成修改后的新值了。
5、重新调试这种调试的回退不是万能的,只能在当前线程的栈帧中回退,也就说最多只能退回到当前线程的调用的开始处。
回退时,请在需要回退的线程方法上点右键,选择"Drop to Frame"6、远程调试用于调试不在本机上的程序,有两种方式,1、本机作为客户端2、本机作为服务端使用远程调试的前提是服务器端和客户端的代码是一致的。
如何运用Eclipse进行Java程序开发

如何运用Eclipse进行Java程序开发第一章:Eclipse简介及安装Eclipse是一个著名的集成开发环境(IDE),可广泛用于Java 程序开发。
它提供了强大的编辑器、调试器和构建工具等功能。
要使用Eclipse进行Java程序开发,首先需要在官方网站上下载并安装Eclipse。
第二章:创建Java项目在Eclipse中创建Java项目非常简单。
首先,打开Eclipse并点击"File"菜单,然后选择"New",再选择"Java Project"。
在弹出的对话框中,输入项目名称并点击"Finish"按钮即可完成创建。
第三章:编写Java代码在Eclipse中编写Java代码非常方便。
点击项目名称右键,选择"New",再选择"Class",在弹出的对话框中输入类名并点击"Finish"按钮。
接下来,会自动生成一个Java类,并在编辑器中打开该类文件。
在编辑器中可以编写Java代码,同时Eclipse提供了代码补全、自动缩进、语法高亮等功能,大大提高了编码效率。
第四章:调试Java程序Eclipse强大的调试器是Java程序开发中的重要工具之一。
要开始调试Java程序,首先需要在代码中设置断点。
断点告诉调试器在某个特定位置停止程序执行,方便我们检查变量的值、跟踪程序的执行流程等。
设置断点只需在编辑器中点击行号旁边的空白处即可。
然后,点击Eclipse工具栏上的"Debug"按钮,Eclipse将在遇到断点时停止程序执行,并显示调试器视图。
通过调试器视图,可以一步一步地执行程序,并观察变量的值,帮助我们找出代码中的问题。
第五章:使用Eclipse构建项目Eclipse提供了强大的构建工具,能够帮助我们自动构建和管理项目。
要构建项目,首先需要在Eclipse中创建构建描述文件,例如Ant脚本或Maven配置等。
使用Eclipse远程调试java应用程序

外文翻译,网上搜索所得Debug Java appli c atio n s remot e ly with Eclip s eU s e the power of the E c lip s e I DE to s prea d aroun d your Java appli c atio n debug g ingLevel : I nter m edia t eC harl e s Lu (c harl e s *********.com),Softw a re E ngin e er, I BM 09 Dec 2008Y ou don't need to debug Java™ appli c atio n s on jus t your loc al des kt o p. Learn how to s prea d aroun d your debug g ing us ing diffe r ent c onne c tion types that make up remot e debug g ing. T his artic l e expla i ns the featu r es and examp l es that s how how to s et up remot e appli c atio n debug g ing.Remot e debug g ing c an be us efu l for appli c atio n devel o pmen t , s uc h as devel o ping a progr a m for a low -end mac hi n e that c anno t hos t the devel o pmen t platf o rm, or debug g ing progr a ms on dedic a ted mac hi n es like Web s erve r s , whos e s ervi c es c anno t be s hut down. O ther examp l es inc lu d e Java appli c atio n s runni n g with limit e d memor y or C P U power , s uc h as mobil e devic e s, or devel o pers wanti n g to s epar a te the appli c atio n and devel o pmen t envir o nmen t s , etc.Prere q uisi t esI f you don't have it alrea d y, downl o ad E c lip s e V3.4 (Ganym e de). I n Ganym e de, the s oc ke t lis te n ing c onne c tor has been added to the Remot e Java A ppli c atio n launc h -c onfi g urat i on type. E c lip s e's new s oc ke t lis te n ing c onne c tor allow s you to s tart the Java debug g er, whic h lis te n s for a c onne c tion on a s pec i f ic s oc ke t . T he progr a m being debug g ed c an then be s tart e d with c omma n d-line optio n s to c onne c t to the debug g er. P rior to the Ganym e de relea s e, only a s oc ke t -attac h ingc onne c tor was provi d ed, and the progr a m being debug g ed had to be a debug hos t that was c onne c ted by the debug g er. I t is impra c tic a l for mobil e devic e s to be a hos t due to ins uf f ic ie n t memor y and C P U power . T o us e remot e debug g ing, Java V irtu a l M ac hi n e (JV M) V5.0 or later mus t be us ed , s uc h as I BM ® J 9 or SunM ic ro s ys te m s ' Java SE Devel o pmen t Kit (JDK). I n this artic l e, we foc us on re mot e debug g ing, rathe r than detai l eac h of E c lip s e's debug g ing featu r es. See Res ou r c es for more infor m atio n about debug g ing with E c lip s e and where to find the afore m enti o ned s oftw a re. JPDA intro d ucti o nSun M ic ro s ys te m s' Java P latf o rm Debug g er A rc hi t ec tu r e (JP DA ) tec hn o logy is a multi t iere d arc hi t ec tu r e that allow s you to debug Java appli c atio n s in all s itua t ions eas il y . T he JP DA c ons i s ts of two inter f ac es (the JV M T ool I nter f ac e and JDI , res pe c tive l y), a proto c ol (Java Debug Wire P roto c ol), and two s oftw a re c ompo n ents that tie them toget h er (bac k -end and front -end). I t's des ig n ed for us e by debug g ers in any envir o nmen t . JP DA is not only for des kt o p s ys te m s but works well with embed d ed s ys te m s , too. T he JV M T ool I nter f ac e (JV M T I ) defin e s that a V M mus t provi d e for debug g ing. (Edito r 's note: Start i ng with Java V5, JV M T I repla c ed JV M DI , whic h was us ed in Java V 1.4.) T he Java Debug Wire P roto c ol (JDWP) des c r i bes the forma t of debug g ing infor m atio n and reque s ts trans f erre d betwe e n the proc e s s being debug g ed and a debug g er front end, whic himplem entsthe JDI, s uc h as E c lips e, Borlan d JBuild er, and many others. T he progra m beingdebugg ed is oftenc alled the debugg ee in Sun's JP DA s pec if ic ati on. T he JDI is a high-levelinterf ac e to define the inform ation and reques ts us ed for remote debugg ing. T he arc hit ec tur e is s truct uredas follow s.Listin g 1. The Java Platfo rm Debugger Archit ectureCompon entsDebugg er Interfaces/ |--------------|/ | VM |debugg ee -----( |--------------| <---- JVMTI - Java VM Tool Interface\ | back-end |\ |--------------|/ |comm channel --( | <------------ JDWP - Java Debug Wire Protocol\ |/ |--------------|/ | front-end |debugg er -----( |--------------| <---- JDI - Java DebugInterface\ | UI |\ |--------------|T heref ore, any third-partytoolsand V M bas edon JP DA s hould work togeth er withou t c ompla int. T his c lient-s erverarc hit ec tur e allows you to debuga Java progra m from a loc alworkst ation runnin g the platfo rm, or even debugit from a remote c omput er on your networ k.f ic ati on: c onnec tor Before talkin g aboutthe debug-s c enar io stuff, we need to introd uc e two termsus ed in the JP DA s pec iand transp ort. A c onnec tor is a JDI abs tra c tion us ed to es tabl is h a c onnec tionbetwee n a debugg er applic ation and a target V M. A transp ort define s how applic ation s ac c ess and transm it data betwee n the frontend and bac k end. T hec onnec tors"map" to the availa ble transp ort typesand the modesof c onnec tion. I n Sun's refere nc e implem entat ion of JP DA, two transp ort mec han is msare provid ed on Mic ros oft® Window s®: s oc ket transp ort and s hared memorytransp ort. A vaila ble c onnec tors:∙Soc ket-attach ing c onnec tor∙Shared-memory attach ing c onnec tor∙Soc ket-lis ten ing c onnec tor∙Shared-memory lis ten ing c onnec tor∙C omman d-line launch ing c onnec torI n es tabl is hin g a c onnec tionbetwee n a debugg er applic ation and target V M, one s ide ac ts as a s erver and lis ten s for a c onnec tion. A t s ome latertime, the others ide attach es to the lis ten er and es tabl is hes a c onnec tion. T he c onnec tionsr. T he c ommun ic ati ons amongproc es s es c an be runnin g allowthe debugg er applic ation or the target V M to ac t as a s erveon one mac hin e or differ ent mac hin es.T he proble m with debugg ing a Java progra m remote ly is not in the debugg er frontend but the remote Java bac k end. U nfort unate ly, thereis not muc h inform ation aboutthis in the E c lips e help s ys tem. I n fac t, JDI and JV M T Iareimplem ented by E c lips e and the Java runtim e enviro nment, res pec tivel y. T he only thingwe are c onc er ned with is the JDWP, whic hc ontai ns the inform ation to c ommun ic ate with the JV M T Iand JDI. T he JDWP c ontai ns many argume nts that have been addedto invoke the applic ation for the remote Java applic ation. Follow ing are s ome of the argume nts us ed in this articl e.-XdebugE nable s debugg ing featur es.-Xrunjd w p:<sub-option s>Loadsthe implem entat ion of JDWP in the target V M. I t us es a transp ort and the JDWP protoc ol toc ommun ic ate with a s epara te debugg er applic ation. Spec if ic s ubopt ionsare des c ri bed below.Starti ng from Java V5, you can us e the -agentl ib:jdwp option, ins tea d of -Xdebug and -Xrunjd wp. But if you have to c onnec t to the V M priorto V5, -Xdebug and -Xrunjd wp will be the only c hoice. Follow ing are briefdes c ri ption s of the -Xrunjd wp s ubopt ions.transportw s platfo rm, Genera lly, s oc ket transp ort is us ed. But s hared-memory transp ort c an als o be us ed on the Windoif availa ble.serverI f the valueis y, the target applic ation lis ten s for a debugg er applic ation to attach. O therw is e, it attach es toa debugg er applic ation at the s pec if ied addres s.addressT his is the transp ort addres s for the c onnec tion.I f the s erver is n, attemp t to attach to a debugg er applic ation at this addres s. O therw is e, lis ten for a c onnec tionat this port.suspendI f the valueis y, the target V M will be s us pen ded untilthe debugg er applic ation c onnec ts.For detail ed explan ation s for eac h debugs ettin g, referto the JP DA doc ume ntati on (see Res our c es).Lis tin g 2s howsan exampl e of how to launch a V M in debugmode and lis ten for a s oc ket c onnec tionat port 8765. Listin g 2. Target VM acts as a debugserverLis tin g 3s howshow to attach to a runnin g debugg er applic ation us inga s oc ket on hos t 127.0.0.1 at port 8000.Listin g 3. Target VM acts as a debugclientE c lips e is a graphi c al Java debugg er frontend. T he JDI is implem ented in org.ec lips e.jdt.debugbundle. I n this articl e, we don't dis c us s the detail s of JDI implem entat ion. See Res our ces for inform ation aboutE c lips e JDT and Java JDItec hno logy.T he firs tthingwe want to know is whic hE c lips e c onnec tor to us e. T o learnthe remote c onnec tiontypesprovid ed by E c lips e, you c an add a launch c onfig urati on in Remote Java Applic ation by goingto the E c lips e menu and s elect ing Run > DebugConf ig urations..., then s elect ing the c onnec tor from the dropdo wn lis t. T wo c onnec torsare provid ed in Ganyme de:∙Soc ket A ttach∙Soc ket Lis tenFor the s oc ket-lis ten ing c onnec tor, the E c lips e V M will be the hos t to be c onnec ted by the remote Java applic ation. For the s oc ket-attach ing c onnec tor, the target VM will be the hos t. T hereis no differ enc efor applic ation debugg ing betwee n the two c onnec tors— the us er may c hoose. A good rule of thumbis to us e the fas ter, more powerf ul c omput er as the V M debughos t bec aus e of the c omput ation al res our c es requir ed.Before debugg ing your Java applic ation, you may need to make s ure the debugoption s are all enable d for your remote applic ation. I f that inform ation is not availa ble, you will get an errormes s ag e, s uc h as"Debuginform ation is not availa ble" or "U nable to ins tal l breakp ointdue to mis s in g line number." Y ou c an modify the s ettin gs from the E c lips e menu by c hangi ng what's s et in Window > Pref er ences > Java > Compiler.Figure 1. Debug options in EclipseDebugan applic ation remote lyWe are readyto s tartdebugg ing an applic ation remote ly. Let's do it step by s tep:1. Create a Java project with a simple classWe c reate a s imple c las sfor debugg ing purpos e. Lis tin g 4s howsthe s ample code.Listin g 4. Sample code f or debugging2. Set a breakp ointSet a breakp ointin the c ode. I n this exampl e, we s et the breakp ointin the line System.out.println("This isa test.");.Figure 2. Set breakp oints in Eclipse3. Debugthe application locallyBefore debugg ing your applic ation, ens ure that the debugoption s des c ri bed in Figure1 are enable d for the projec t. I t's unnece s s ary to debugan applic ation loc all y, but we c an make s ure all the debuginform ation is availa ble. Right-c lic kon the Java projec t, s elect Debug As and s elect Java Applic ation(s ee Figure3). I f the applic ation exec ut ion is s toppe d at the breakp oint,the debugg ing inform ation is pres en ted c orrec tly. Y ou c anc ontin ue to us e the debugg ing featur es, s uc h as dis pla yingthe debugs tac k, variab les, or breakp ointmanage ment, etc.Figure 3. Debug the applic ation locally4. Export the Java projectWe will us e this applic ation as the debugtarget. Right-c lic kon the Java projec t, s elect Export, s elect Java, then c hoose JAR f ile or Runnable JAR f ile to export the projec t. T he JA R file will be genera ted at the des ire d loc ati on. Be awarethat if the Java s ource does not matc hthe target applic ation, the debugfunc ti on will not work c orrec tly.5. Run the Java applic ation manuallyO pen a c ons ol e to launch the applic ation manual ly to make s ure the Java runtim e enviro nment is c onfig uredproper ly.Listin g 5. Sample to invoke Java application6. Debugthe application remote lyC opy the JA R file to the approp riate loc ati on on the remote c omput er, or even the s ame mac hin e, invoke thedebugs erver, and then attach a c lient to it. T he s imple Java applic ation c an ac t as a debugs erver or c lient.Depend ing on the c onfig urati on, you c an c hoose either Socket Attach or Socket Listen c onnec tiontype inE c lips e. Learnhow to run the applic ation as a s erver or c lient in the follow ing two s ec tio ns.Target VM acts as debugserverT he follow ing exampl e invoke s the Java applic ation on the remote s ide, ac ts as a debugs erver, and lis ten s for a s oc ket c onnec tionon port 8000. T he target V M will be s us pen ded untilthe debugg er c onnec ts.Listin g 6. VM invoca tion sample f or socket attach ing mode in EclipseStartE c lips e us ingthe remote launch c onfig urati on and specif y the target V M addres s of the remote applic ation. T o do this, c lic kRun > Debug Conf ig urati ons, and double-c lic kthe Remote Java Applic ation in the E c lips e menu. From the newlyc reate d launch c onfig urati on, s pec if y the IP and port for target applic ation. T o run the remote applic ation in the s ame mac hin e, s imply s pec if y the hos t I P as loc alh ost or 127.0.0.1.Figure 4. Conf ig urati on of socket-attach ing connec tionSelect Allowtermination of remote VM option to termin ate the V M to whic hyou are c onnec tingduring applic ation debugg ing.Figure 5. Terminate button in EclipseTarget VM acts as debugclientT he s ec ond exampl e is to us e a s imple Java applic ation that ac ts as a debugc lient, and the debugg er frontend ac ts as a debugs erver. E c lips e us es the s oc ket lis ten-mode c onnec tiontype for lis ten ing. T he debugfrontend mus t be s tarte d in advanc e to lis ten on a s pec if ic port. Figure 6s howsa s ample c onfig urati on to s et up lis ten ing.Figure 6. Conf ig urati on of socket-listen ing connec tionC lic kthe E c lips e Debugbutton, and the s tatus bar will show the mes s ag e "waitin g for vm to c onnec t at port 8000..." When you s ee that, s tartthe remote applic ation. Lis tin g 7s howshow to invoke the Java applic ation as a debugc lient and attach it to a runnin g debugg er applic ation us inga s oc ket on hos t 127.0.0.1 at port 8000.Listin g 7. VM invoca tion sample f or socket-listen ing connectionin EclipseI f everyt hinggoes well, the debugpers pe c tive will be dis pla yed to s uppor t the applic ation debugg ing, and the exec ut ion of the remote Java applic ation will be s toppe d normal ly. T his is s imila r to Step 3 that we did in loc aldebugg ing (s ee Figure3). A t this point, you c an us e s tanda rd debugg ing func ti ons, s uc h as s ettin g breakp oints and values, s tep exec ut ion, etc.Conclu sionT his articl e illust rated how to us e the E c lips e built-in remote Java applic ation c onfig urati on type to perfor m applic ation debugg ing remote ly. I t introd uc edhow to s et up a Java applic ation to invoke remote debugg ing and helped you unders tandthe c onnec torsE c lips e provid es. Finall y, you learne d how to applythis tec hno logyto your projec ts. Resour cesLearn∙"E c lips e Ganyme de at a glance" is an overvi ew of s evera l Ganyme de projec ts, alongwith res our c es for more inform ation.∙For an introd uc tio n to the debugg ing with the E c lips e platfo rm, s ee "Debugg ing with the E c lips e P latfo rm."∙E xpand your E c lips e debugg ing knowle dge by c hec ki ng out E c lips e Debugg ing Res our c es.∙Learnmore aboutJava P latfo rm Debugg er A rc hit ec tur e by Sun M ic ros ys tem s.∙Read the Java P latfo rm Debugg er A rc hit ec tur e doc ume ntati on to learnmore aboutJPDA.∙Read the Java DebugI nterf ac e doc ume ntati on to learnmore aboutJDI.∙T he JDT projec t provid es the tool plug-ins that implem ent a Java I DE s uppor tingthe develo pment of any Java applic ation, inc lud ing E c lips e plug-ins.∙C hec kout the "Rec omm ended E c lips e readin g list."∙Browse all the Eclips e c onten t on develo perWo rks.∙N ew to E c lips e? Read the develo perWo rks articl e "Get s tarte d with E c lips e P latfo rm" to learnits origin and arc hit ec tur e, and how to extend E c lips e with plug-ins.∙E xpand your E c lips e s kills by c hec ki ng out I BM develo perWo rks' E c lips e projec t res our c es.∙T o lis ten to intere s ting interv iewsand dis c us s ions for s oftwa re develo pers, c hec kout c hec kout develo perWo rks podc as ts.∙Stay c urren t with develo perWo rks' T ec hni c al events and webc as ts.∙Watc hand learnaboutI BM and open s ource tec hno logie s and produc t func ti ons with the no-c ost develo perWo rks O n demand demos.∙C hec kout upc omi ng c onfer enc es, trades hows, webc as ts, and otherE vents around the worldthat are of intere s t to IBM open s ource develo pers.∙V is itthe develo perWo rks O pen s ource zone for extens ive how-to inform ation, tools, and projec t update s to help you develo p with open s ource tec hno logie s and us e them with I BM's produc ts.Get produc ts and tec hno logie s∙T he Java 2Standa rd E ditio n V5 or greate r is availa ble from Sun M ic ros ys tem s.∙C hec kout the latest E c lips e tec hno logydownlo ads at IBM alphaW orks.∙Downlo ad E c lips e P latfo rm and otherprojec ts from the E c lips e Founda tion.∙Downlo ad I BM produc t evalua tionvers io ns, and get your handson applic ation develo pment toolsand middle wareproduc ts from DB2®, Lotus®, Ration al®, T ivoli®, and WebSph ere®.∙I nnova te your next open s ource develo pment projec t with I BM trials oftwa re, availa ble for downlo ad or on DVD.A boutthe authorC harle s Lu is a s oftwa re develo per at the I BM C hinaSoftwa re Develo pment Lab and c urren tly workson I BM LotusE xpedi tor develo pment. H e is intere s tedin device progra mming, ins tan t mes s ag ing, and voic etec hno logy.本文来自于:/develo perwo rks/java/librar y/os-eclips e-javade bug/index.html?S_TACT=105 AGX02&S_CMP=EDU使用 Eclips e 远程调试Java 应用程序利用 Eclips e IDE 的强大功能远程调试Java 应用程序级别:中级Charle s Lu, 软件工程师, IBM2009年12月9日在本地计算机上调试Java™ 应用程序并不是惟一的选择。
java ee开发环境搭建及项目调试实验总结

java ee开发环境搭建及项目调试实验总结在Java EE开发过程中,正确搭建开发环境是非常重要的,它可以提高我们的工作效率,使我们能够快速开发和调试项目。
在这篇文章中,我将总结我的JavaEE开发环境搭建及项目调试实验过程。
首先,为了搭建Java EE开发环境,我们需要准备以下工具和软件:Java JDK、Eclipse IDE、Tomcat服务器和MySQL数据库。
请确保您已经正确安装了这些软件,并且它们之间没有任何冲突。
接下来,我们要配置Eclipse IDE。
首先,打开Eclipse并点击“File”菜单,然后选择“New”和“Java Project”。
在打开的对话框中,我们可以给项目起一个名称,并确保选择了正确的JRE。
然后点击“Finish”按钮创建一个新的Java项目。
下一步是导入Java EE相关的库文件。
在项目资源管理器中,右键单击创建好的Java项目,然后选择“Properties”选项。
在打开的对话框中,选择“Java Build Path”并点击“Add Library”按钮。
在下一个对话框中,选择“Server Runtime”并选择已经安装的Tomcat服务器。
点击“Finish”完成配置。
现在,我们可以开始进行实验项目的调试了。
首先,我们要创建一个简单的Java EE项目。
在项目资源管理器中,右键单击Java项目并选择“New”和“Dynamic Web Project”。
在打开的对话框中,给项目起一个名称,并选择正确的目标运行环境。
然后,点击“Next”并按照提示选择需要的配置选项。
最后,点击“Finish”按钮创建项目。
在项目中,我们可以创建Java类、Servlet和JSP页面来实现所需的功能。
使用Eclipse的开发工具,我们可以方便地编写和调试代码。
在编写完代码后,我们可以通过单击“Run”按钮启动Tomcat服务器,并在浏览器中访问项目来测试和调试。
学习使用Eclipse进行高级的Java开发和调试技巧

学习使用Eclipse进行高级的Java开发和调试技巧第一章:Eclipse简介Eclipse是一个著名的集成开发环境(IDE),用于开发各种编程语言,特别是Java。
它的功能强大,易于使用,可以大大提高开发人员的效率。
本章将介绍Eclipse的基本特点和常用功能。
1.1 Eclipse的特点Eclipse是一个开源软件,支持多种操作系统,具有可扩展性强的插件体系结构,可以根据需要安装各种插件来扩展其功能。
它具有代码补全、代码导航、错误提示、代码重构等功能,使得编写代码更加便捷高效。
1.2 Eclipse的安装和配置要使用Eclipse进行高级的Java开发和调试技巧,首先需要下载并安装Eclipse。
安装后,可以根据需要进行一些基本的配置,如设置工作区、选择编译器版本等。
第二章:Java项目的创建与管理2.1 创建Java项目在Eclipse中创建Java项目非常简单。
选择File -> New -> Java Project,然后按照提示进行操作即可。
同时,可以设置项目名称、路径、源文件夹等。
2.2 导入和导出Java项目可以将已经存在的Java项目导入到Eclipse中,选择File -> Import -> Existing Projects into Workspace,然后选择要导入的项目即可。
同样,可以将项目导出为可执行的JAR文件或WAR文件,以便于分发和部署。
2.3 项目的管理Eclipse提供了多种管理项目的功能。
可以通过Package Explorer或Project Explorer视图来查看和管理项目的文件和文件夹结构,可以创建和删除源文件、包和类,可以设置类路径和库引用等。
第三章:编辑和调试Java代码3.1 编写Java代码在Eclipse中,可以通过打开一个Java源文件来编辑代码。
Eclipse提供了代码补全、语法高亮、代码折叠等功能,大大提高了编辑的效率和质量。
使用Eclipse进行Java开发的高级技巧与调试方法

使用Eclipse进行Java开发的高级技巧与调试方法Java开发是当今软件开发领域中最为广泛应用的编程语言之一。
而Eclipse作为一款强大的集成开发环境(IDE),不仅提供了丰富的功能和工具,还可以帮助开发人员更高效地进行Java开发。
本文将介绍一些使用Eclipse进行Java开发的高级技巧与调试方法,帮助开发人员更好地利用这个工具进行开发。
一、使用Eclipse的代码自动补全功能Eclipse提供了强大的代码自动补全功能,可以极大地提高开发效率。
在编写代码的过程中,只需输入几个字符,Eclipse就会自动提示可能的代码片段,并在选择后自动补全。
开发人员可以通过按下“Ctrl + 空格”来手动触发代码自动补全功能。
此外,Eclipse还可以根据已有的代码上下文进行智能提示,帮助开发人员更快地找到需要的代码。
二、使用Eclipse的快捷键加速开发熟练掌握Eclipse的快捷键可以大大提高开发效率。
例如,使用“Ctrl + 1”可以快速修复代码中的错误,使用“Ctrl + Shift+ O”可以自动导入缺失的包,使用“Ctrl+ Shift + F”可以自动格式化代码等等。
这些快捷键可以帮助开发人员更快地完成常见的开发任务,减少不必要的鼠标操作,提高开发效率。
三、使用Eclipse的调试功能调试是开发过程中常用的技术手段,可以帮助开发人员找出代码中的错误和问题。
Eclipse提供了强大的调试功能,可以帮助开发人员逐行执行代码,查看变量的值以及调用栈信息等。
在进行调试时,可以设置断点,使程序在特定的位置暂停执行,以便开发人员观察代码的执行情况。
此外,Eclipse还提供了条件断点、表达式求值等高级调试功能,帮助开发人员更好地定位和解决问题。
四、使用Eclipse的代码重构功能代码重构是一种对代码进行结构上的改变,以提高代码质量和可维护性的技术手段。
Eclipse提供了丰富的代码重构功能,可以帮助开发人员快速、安全地进行代码重构。
eclipse调试java程序的九个技巧

eclipse调试java程序的九个技巧九个技巧:1. 逻辑结构2. 条件debug3. 异常断点4. 单步过滤5. 跳到帧6. Inspect7. expressions8. display9. 远程debug 最早开始⽤eclipse的debug的时候,只会F5 F6 F7 F8,甚⾄F7都不是很搞的明⽩是怎么⽤的,那时候资浅,碰不到需要复杂debug的代码,慢慢⼯作深⼊了,场景碰多了,就需要各种debug技巧来提升定位bug效率,以前找⼈帮忙排查问题,看他开各种窗⼝debug各种溜甚是羡慕嫉妒恨,慢慢久病成医⾃⼰也⽤溜了eclipse的⼀些主要的debug技巧。
稍作整理分享出来。
F5678这四个基本技能就略过不说了,但是最基本的技能能解决90%问题,所以虽然略过不说,但是必须⽤的很溜,相信园友达⼈们这四个肯定⽐我⽤的溜的多。
1. 逻辑结构逻辑结构主要⽤来展⽰map之类的collection数据结构存储的值的,它只展⽰存储值的逻辑部分,⽽屏蔽了数据结构详细的内部结构,更⽅便我们查看map之类collection结构⾥存储的值,推荐使⽤。
这个按钮就是展⽰逻辑结构的按钮,下⾯两个图,上图是不展⽰逻辑结构,下图是展⽰逻辑结构,很明显,下图的结构可读性更强,可以专注于debug的变量。
2. 条件debug条件debug⽤在需要满⾜某种条件才会触发断点的场景,⽐如只有id是12345这条记录会有问题,那就当id等于12345时才触发断点,其他都放过。
右击断点选择断点属性,就能看到这样⼀个配置框,右边的⽂本区块可以填写条件代码,⽐如id==12345,由于每次都要做这个判断,如果循环数很⼤的话,还是有点点慢的,你可以去上个厕所接个⽔啊什么的,还是很⽅便的。
3. 异常断点异常断点只要⽤在debug某种异常的时候,可以配置当这个异常出现后才触发断点,不需要debug去寻找异常。
点击这个红圈就能弹出异常断点的窗⼝,会列出你系统⾥的所有异常类,然后选择需要断点的异常就OK。
实训1.用ECLIPSE调试我的第一个JAVA程序

实训1用eclipse调试我的第一个Java程序一、相关知识点Java语言的出现源于“平台无关性”,用这种语言编写的程序,不会因为芯片的变化而发生无法运行的情况。
随着计算机网络的迅速发展,Java语言的优势越来越明显。
Sun公司为实现“编写一次,到处运行”(write once,run anywhere.)的目标,提供了Java运行平台的3个主要版本。
1.J2SE:Java标准平台(SDK,又称JDK),可以开发Java桌面应用程序、低端服务器应用程序和Java Apple程序。
2.J2EE:Java企业平台,在J2SE的基础上增加了附加类库,以支持目录管理、交易管理和企业级消息处理等功能。
3.J2ME:Java小型平台。
用于嵌入式的小系统中,如移动电话和掌上电脑等。
以上各种Java运行平台,都包括了相应的Java虚拟机(Java Virtual Machine),虚拟机负责将*.class文件加载到内存,然后用解释方式来执行*.class文件。
J2SE(JDK)是学习Java语言的最佳平台。
二、实训目的1.掌握开发Java应用程序的3个基本步骤,编写源文件、编译源文件和运行应用程序。
2.初步了解Eclipse的使用。
三、实训内容及要求1.编写一个简单的Java应用程序,该程序在Eclipse的控制台窗口中输出4行文字:“我们是医生,”、“如何对待病人,”、“如何对待人民大众,”和“是我们终身都要面对的问题。
”运行结果参见图1-1。
图1-1我的第一个Java程序的输出2.将以上程序改编成Java Applet程序运行。
运行结果参见图1-2。
图1-2Applet小程序运行结果3.(选做)自行添加HTML程序,使改编后的Java Applet程序可以在浏览器中运行。
运行结果参见图1-3。
图1-3在HTML文件中运行Apple小程序的结果四、实训参考程序(1)firstprogram.java//这是我的第一个JAVA程序//程序的名称为"firstprogram.java"public class firstprogram{public static void main(String[]args){System.out.println("我们是医生,");System.out.println("如何对待病人,");System.out.println("如何对待人民大众,");System.out.println("是我们终身都要面对的问题。
学习使用Eclipse进行Java应用开发和调试

学习使用Eclipse进行Java应用开发和调试Chapter 1: Eclispe简介和安装Eclipse是一个开放源代码的集成开发环境(IDE),广泛用于Java应用程序的开发和调试。
在这一章节中,我们将介绍Eclipse的基本概念和功能,并提供详细的安装步骤。
1.1 Eclipse概述Eclipse是一个由Eclipse基金会开发的自由开源的IDE,支持多种编程语言,其中包括Java。
它提供了一套强大的工具和插件,用于简化Java应用程序的开发、调试和测试。
1.2 Eclipse的安装步骤下面是安装Eclipse的简单步骤:1) 打开Eclipse官方网站,并下载适用于您操作系统的最新版Eclipse。
2) 解压下载的压缩文件到您选择的目录。
3) 在解压的目录中找到eclipse.exe(Windows)或eclipse(Mac/Linux)文件,并运行它。
Chapter 2: 创建和配置Java项目在这一章节中,我们将学习如何使用Eclipse创建和配置Java 项目。
我们将介绍项目的基本设置,包括项目名称、文件结构和依赖项管理。
2.1 创建一个新的Java项目在Eclipse中创建一个新的Java项目非常简单:1) 打开Eclipse并选择File -> New -> Java Project。
2) 输入项目名称,并选择所需的JRE版本。
3) 点击Finish按钮,完成项目的创建。
2.2 配置Java项目一旦项目创建完成,我们可以进行一些基本的配置:1) 在项目上点击右键,并选择Properties菜单项。
2) 在弹出的窗口中,您可以设置项目的构建路径、类路径和其他相关配置。
Chapter 3: 编写和调试Java代码在这一章节中,我们将学习如何在Eclipse中编写和调试Java 代码。
我们将介绍Eclipse提供的代码编辑和调试工具,以及如何使用这些工具来提高开发效率和调试准确性。
Eclipse调试Java的10个小窍门

你可以已经看过一些类似“关于调试的N件事”的文章了。
但我想我每天大概在调试上会花掉1个小时,这是非常多的时间了。
所以非常值得我们来了解一些用得到的功能,可以帮我们节约很多时间。
所以在这个主题上值得我再来写一篇文章。
第一条:不要过分的调试!有关调试的第一条要牢记的便是这条很疯狂的口号!但是我必须要在这里再说一遍:不要过分的调试!试着将复杂的逻辑分解成独立的小单元,然后写单元测试代码来保证小单元的正确运行。
我经常看到某些人会这么做:在一个大型的Web应用上点击,填了几个表单,跳转了多个页面,只是为了确认最后一个页面的结果的正确性,最后在调试视图下来开发代码。
在你开启tomcat之前,应该要先问问自己:有没有什么方法可以用单元测试来检测代码的行为呢?你可以找到很多教你如何写出好的代码的教程。
而这里我主要来谈一谈Eclipse的调试功能,你可能不知道,或者长时间以来有些淡忘的功能。
调试视图:有条件的断点如果你仅仅对程序的某个部分感兴趣,调试视图是非常有帮助的。
假设你想看看一个循环中的第十三次循环得到什么结果,或者你正在调试一个抽象父类,想看看某个具体的子类。
你可以在调试视图设置条件,右键点击代码旁的蓝色断点符号,在弹出菜单中选择“Breakpoint Properties…”。
你可以选择是在你的代码段返回真值是停止程序或者当你的代码段的值改变时停止。
变量视图:显示逻辑结构(Show Lodical Structure)如果你想在变量视图中查看Map或者List中的值,eclipse的默认设置可能不是那么方便。
譬如你在使用HashMap,你必须要点开所有的子节点才能看到HashMap中的内容,还要受到HashMap实现细节的干扰。
但是在变量上有一个小按钮-“Show Logical Structure”。
它非常的方便,尤其当你没有实现某个对象的toString()代码时。
我的老板前几个星期刚刚告诉我Eclipse有这个功能。
学会使用Eclipse插件进行Java调试和测试

学会使用Eclipse插件进行Java调试和测试第一章:引言Eclipse是一款功能强大的集成开发环境(IDE),它提供了丰富的插件来帮助开发人员进行Java调试和测试。
本文将介绍如何使用Eclipse插件来提高Java开发的效率和质量。
首先,我们将详细介绍Eclipse的调试功能,然后探讨如何使用插件进行单元测试和性能测试。
第二章:Eclipse的调试功能Eclipse提供了强大的调试功能,可以让开发人员追踪代码的执行过程并检查变量的值。
首先,我们需要设置断点,断点是我们希望在程序执行到特定位置时暂停执行的标记。
然后,我们可以运行程序,并在程序执行到断点时暂停。
在暂停状态下,我们可以通过查看变量视图和表达式视图来检查程序的状态和值。
另外,Eclipse还提供了单步执行、逐过程执行和跳过断点等功能,以帮助我们更好地理解和调试程序。
第三章:使用Eclipse插件进行单元测试单元测试是用于测试最小的可测试单元(通常是方法或函数)是否按照预期工作的方法。
Eclipse通过插件JUnit来支持单元测试。
首先,我们需要创建一个JUnit测试类,该类包含了一些用于测试的方法。
然后,我们可以使用JUnit的各种断言方法来验证方法的预期输出和行为。
在Eclipse中,我们可以选择运行整个测试类或特定的测试方法。
通过运行测试,Eclipse将自动为我们生成测试报告,显示测试覆盖率和失败的测试用例。
第四章:使用Eclipse插件进行性能测试性能测试是用于评估系统在不同负载条件下的性能和稳定性的过程。
Eclipse通过插件JMeter来支持性能测试。
首先,我们需要创建一个JMeter测试计划,该计划包含了一系列测试步骤和负载设置。
然后,我们可以使用JMeter的各种Sampler和Listener来模拟用户行为和监视测试结果。
在Eclipse中,我们可以选择运行整个测试计划或特定的测试步骤。
通过运行测试,Eclipse将自动为我们生成测试报告,显示请求响应时间、吞吐量和错误率等重要指标。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
华章培训
第13页
1、修复作业文件夹里的代码。
总结及作业
14
感谢您对华章培训网的支持!
http://www.
transport:这里通常使用套接字传输。但是在 Windows 平台上也可以使用共享
内存传输。 Server:如果值为 y,目标应用程序监听将要连接的调试器应用程序。否则,它 将连接到特定地址上的调试器应用程序。 address:这是连接的传输地址。如果服务器为 n,将尝试连接到该地址上的调试 器应用程序。否则,将在这个端口监听连接。 suspend:如果值为 y,目标 VM 将暂停,直到调试器应用程序进行连接。
华章培训
第10页
1、被调试程序当作调试服务器。
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8765
2、被调程序当作调试客户端。
-Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8000
华章培训
第8页
远程调试原理
通过客户机-服务器架构,可以在本地调试 Java 程序,也可以通过网络进行远程调试, JPDA 规范中的两个术语:连接器和传输。连接器是一个 JDI 抽象,用来在调试器应用
程序和目标 VM 之间建立连接。传输定义应用程序如何进行访问,以及数据如何在前端
第2页
断点的实现原理
断点(Break Point)可以说是调试器的关键技术,需要软件和硬件的协作才能实现。一 般断点的实现方式有下面几种:
1. 通过特定的指令通知中央处理器(CPU)来中断程序的执行。
2. 通过设置特定的寄存器来通知中央处理器中断程序的执行。 3. 通过强制处理器触发异常来中断程序执行并将控制权转交给调试器。 在 Intel兼容的处理器架构上,一般调试器是通过在进程中特定的位置插入INT 3指令来 实现断点的。 调试器提供的单步执行,单步跳过执行以及跳出凼数等功能,都是断点的变种。
和后端之间传输。连接器 “映射” 到可用的传输类型和连接模式。在 Sun 的 JPDA 参 考实现中,为 Microsoft® Windows® 提供了两个传输机制:套接字传输和共享内存 传输。可用的连接器:
• 连接套接字连接器
• 连接共享内存连接器 • 监听套接字连接器 • 监听共享内存连接器
• 启劢命令行连接器
华章培训
第9页
远程调试命令参数
-Xdebug: 启用调试特性。 -Xrunjdwp:<sub-options> :在目标 VM 中加载 JDWP 实现。它通过传输和 JDWP
协议不独立的调试器应用程序通信。下面介绍一些特定的子选项。
从 Java V5 开始,您可以使用 -agentlib:jdwp 选项,而丌是 -Xdebug 和 -Xrunjdwp 。但如果连接到 V5 以前的 VM,只能选择 -Xdebug 和 -Xrunjdwp。 -Xrunjdwp 子选项。
第7页
远程调试架构
Java平台调试器架构
组件 / / 被调程序 -----( \ \ / 通信渠道 --( \ / / 调试器 -----( \ \
调试器接口 |--------------| | VM | |--------------| <---- JVMTI – Java虚拟机工具接口 | 后台 | |--------------| | | <------------ JDWP – Java调试传输协议 | |--------------| | 前台 | |--------------| <---- JDI – Java调试接口 | UI | |--------------|
第一讲使用Eclipse以及JDB调试Java程序
应用程序调试技术(Java部分)
主讲人: 施懿民
华章培调试的原理,使用Eclipse调试器的一些技巧,以及使用 jdb调试Java程序的方法。
华章培训
华章培训
第3页
1、在C程序中嵌入断点。
演示
第4页
特殊断点
除了简单的每次执行到断点位置中断程序执行这一种方式,调试器一般都提供了如下几 种断点:
1. 条件断点 – 可以指定触发断点的条件,避免每次重复触发断点降低调试工作效率。
2. 监视断点 – 可以在访问数据的时候,中断程序的执行。 3. 凼数断点 – 可以在执行凼数前或者退出凼数前中断程序的执行。 4. 异常断点 – 当程序发生指定异常的时候,中断程序的执行,第一时间发现问题所在。 5. 类型断点 – 当程序试图加载某个类型的时候,中断程序的执行。
华章培训
第5页
1、禁用所有的断点。
2、设置条件断点。 3、监视断点。
4、异常断点。
5、凼数断点。 6、在类型加载的时候中断
演示
第6页
1、在堆栈的任意位置重新执行语句。 2、在程序启劢时进行调试。
3、使用变量窗口的逻辑视图。
4、单步过滤调试。 5、计算表达式。
演示 – Eclipse其他调试技巧
演示 – 设置远程调试
第11页
1、使用jdb调试java程序。
演示
第12页
在Emacs里运行JDB
由于直接使用JDB调试时,浏览源代码时很丌方便,如果机器上安装了emacs,可以直 接在emacs里启劢JDB,获取跟eclipse相近的源代码级别的调试体验。 在emacs里运行JDB的方法: 1.在emacs里按下ALT+X键,在提示符后面输入JDB,敲击回车。 2.接着再输入JDB的启劢参数。 3.按下CTRL + X,2键,将emacs分屏。 4.再按CTRL + X, B键,将其中一个屏幕显示源代码。 5.按CTRL + X, O键,再两个屏幕间切换。 6.在JDB的那个窗口里输入正常的调试命令。