Eclipse 简明教程
Eclipse - Overview
What is Eclipse?
在计算的背景下,Eclipse 是一个用于使用 Java 编程语言和其他编程语言(如 C/C++、Python、PERL、Ruby 等)开发应用程序的集成开发环境 (IDE)。
In the context of computing, Eclipse is an integrated development environment (IDE) for developing applications using the Java programming language and other programming languages such as C/C++, Python, PERL, Ruby etc.
为 Eclipse IDE 提供基础的 Eclipse 平台由插件组成,并且设计为可以使用其他插件进行扩展。Eclipse 平台使用 Java 开发,可以用于开发富客户端应用程序、集成开发环境和其他工具。Eclipse 可用作任何有插件提供的编程语言的 IDE。
The Eclipse platform which provides the foundation for the Eclipse IDE is composed of plug-ins and is designed to be extensible using additional plug-ins. Developed using Java, the Eclipse platform can be used to develop rich client applications, integrated development environments and other tools. Eclipse can be used as an IDE for any programming language for which a plug-in is available.
Java 开发工具 (JDT) 项目提供了一个插件,允许 Eclipse 用作 Java IDE,PyDev 是一个允许 Eclipse 用作 Python IDE 的插件,C/C 开发工具 (CDT) 是一个插件,允许 Eclipse 用作开发使用 C/C 的应用程序,Eclipse Scala 插件允许 Eclipse 用作 IDE 开发 Scala 应用程序,而 PHPeclipse 是一个 Eclipse 插件,为 PHP 提供完整的开发工具。
The Java Development Tools (JDT) project provides a plug-in that allows Eclipse to be used as a Java IDE, PyDev is a plugin that allows Eclipse to be used as a Python IDE, C/C Development Tools (CDT) is a plug-in that allows Eclipse to be used for developing application using C/C, the Eclipse Scala plug-in allows Eclipse to be used an IDE to develop Scala applications and PHPeclipse is a plug-in to eclipse that provides complete development tool for PHP.
Licensing
Eclipse 平台和 Eclipse 基金会提供的其他插件根据 Eclipse 公共许可证 (EPL) 发布。EPL 确保 Eclipse 可以免费下载和安装。它还允许修改和分发 Eclipse。
Eclipse platform and other plug-ins from the Eclipse foundation is released under the Eclipse Public License (EPL). EPL ensures that Eclipse is free to download and install. It also allows Eclipse to be modified and distributed.
Eclipse Releases
自 2006 年以来,Eclipse 基金会每年 6 月都会发布 Eclipse 平台和许多其他插件。
Every year, since 2006, the Eclipse foundation releases the Eclipse Platform and a number of other plug-ins in June.
Codename |
Year |
Platform Version |
Callisto |
2006 |
3.2 |
Europa |
2007 |
3.3 |
Ganymede |
2008 |
3.4 |
Galileo |
2009 |
3.5 |
Helios |
2010 |
3.6 |
Indigo |
2011 |
3.7 |
Juno |
2012 |
3.8 and 4.2 |
Kepler |
2013 |
4.3 |
Luna |
2014 |
4.4.0 |
Eclipse - Installation
Downloading Eclipse
您可以从 http://www.eclipse.org/downloads/ 下载 Eclipse。下载页面列出了 Eclipse 的多个版本。
You can download eclipse from http://www.eclipse.org/downloads/. The download page lists a number of flavors of eclipse.
每个 Eclipse 封装的功能各不相同。Java 开发人员通常使用 Eclipse Classic 或 Eclipse IDE 开发 Java 应用程序。
The capabilities of each packaging of eclipse are different. Java developers typically use Eclipse Classic or Eclipse IDE for developing Java applications.
下载页面右上角的下拉框允许您设置安装 Eclipse 的操作系统。您可以在 Windows、Linux 和 Mac 之间进行选择。Eclipse 以 zip 文件打包。
The drop down box in the right corner of the download page allows you to set the operating system on which eclipse is to be installed. You can choose between Windows, Linux and Mac. Eclipse is packaged as a zip file.
Installing Eclipse
要在 Windows 上安装,您需要一个可以解压 zip 文件的工具。例如,您可以使用 −
To install on windows, you need a tool that can extract the contents of a zip file. For example you can use −
使用其中任何一种工具将 Eclipse zip 文件的内容解压到您选择的任何文件夹。
Using any one of these tools, extract the contents of the eclipse zip file to any folder of your choice.
Launching Eclipse
在 Windows 平台上,如果您将 zip 文件的内容解压到 c:\,则可以使用 c:\eclipse\eclipse.exe 启动 Eclipse。
On the windows platform, if you extracted the contents of the zip file to c:\, then you can start eclipse by using c:\eclipse\eclipse.exe
当 Eclipse 首次启动时,它会提示您工作空间文件夹的位置。您的所有数据都将存储在工作区文件夹中。您可以接受默认设置或选择一个新位置。
When eclipse starts up for the first time it prompts you for the location of the workspace folder. All your data will be stored in the workspace folder. You can accept the default or choose a new location.
如果您选择“将其用作默认设置,并且不再询问”,则此对话框将不再弹出。您可以使用工作空间首选项页面更改此首选项。有关更多详细信息,请参见 Preference tutorial 页面。
If you select "Use this as the default and do not ask again", this dialog box will not come up again. You can change this preference using the Workspaces Preference Page. See the Preference tutorial page for more details.
Eclipse - Explore Windows
Parts of an Eclipse Window
Eclipse 窗口的主要可视部分为 −
The major visible parts of an eclipse window are −
-
Views
-
Editors (all appear in one editor area)
-
Menu Bar
-
Toolbar
Eclipse 透视图是一个名称,指代最初收集和排列的视图以及一个编辑器区域。默认透视图称为 Java。Eclipse 窗口可以在其中打开多个透视图,但任何时候只能激活一个透视图。用户可以在打开的透视图之间切换,或打开一个新透视图。透视图控制在某些菜单和工具栏中显示的内容。
An eclipse perspective is the name given to an initial collection and arrangement of views and an editor area. The default perspective is called java. An eclipse window can have multiple perspectives open in it but only one perspective can be active at any point of time. A user can switch between open perspectives or open a new perspective. A perspective controls what appears in some menus and tool bars.
一个透视图只有一个编辑器区域,可以在其中打开多个编辑器。编辑器区域通常周围环绕着多个视图。通常,编辑器用于编辑项目数据,而视图则用于查看项目元数据。例如,包浏览器显示了项目中的 Java 文件,而 Java 编辑器用于编辑 Java 文件。
A perspective has only one editor area in which multiple editors can be open. The editor area is usually surrounded by multiple views. In general, editors are used to edit the project data and views are used to view the project metadata. For example the package explorer shows the java files in the project and the java editor is used to edit a java file.
Eclipse 窗口可以包含多个编辑器和视图,但任何时候只有一个处于活动状态。活动编辑器或视图的标题栏看起来与其他所有编辑器或视图不同。
The eclipse window can contain multiple editors and views but only one of them is active at any given point of time. The title bar of the active editor or view looks different from all the others.
菜单栏和工具栏上的 UI 元素表示可以由最终用户触发的命令。
The UI elements on the menu bar and tool bar represent commands that can be triggered by an end user.
Using Multiple Windows
可以同时打开多个 Eclipse 窗口。要打开一个新窗口,请单击“窗口”菜单并选择“新建窗口”菜单项。
Multiple Eclipse Windows can be open at the same time. To open a new window, click on the Windows menu and select the New Window menu item.
每个窗口都可以打开一个不同的透视图。例如,您可以打开两个 Eclipse 窗口,一个在 Java 透视图中,另一个在调试透视图中。显示 Java 透视图的窗口可用于编辑 Java 代码,而显示调试透视图的窗口可用于调试正在开发的应用程序。
Each window can have a different perspective open in them. For example you could open two Eclipse windows one in the Java perspective and the other in the Debug perspective. The window showing the Java perspective can be used for editing the java code and the window showing the debug perspective can be used for debugging the application being developed.
Eclipse - Explore Menus
Typical Eclipse Menus
Eclipse 窗口的菜单栏上一般有这些菜单:
The typical menus available on the menu bar of an Eclipse window are −
-
File menu
-
Edit menu
-
Navigate menu
-
Search menu
-
Project menu
-
Run menu
-
Window menu
-
Help menu
插件可以添加新的菜单和菜单项。例如,当 Java 编辑器打开时,你将看到源代码菜单,当 XML 编辑器打开时,你将看到 {s0} 菜单。
Plug-ins can add new menus and menu items. For example when the java editor is open you will see the Source menu and when the XML editor is open, you will see the Design menu.
Brief Description of Menus
Sr.No |
Menu Name & Description |
1 |
File The File menu allows you to open files for editing, close editors, save editor content and rename files. Among the other things, it also allows you to import and export workspace content and shutdown Eclipse. |
2 |
Edit The Edit menu presents items like copy & paste. |
3 |
Source The Source menu is visible only when a java editor is open. It presents a number of useful menu items related to editing java source code. |
4 |
Navigate The Navigate menu allows you to quickly locate resources and navigate to them. |
5 |
Search The Search menu presents items that allow you to search the workspace for files that contain specific data. |
6 |
Project The menu items related to building a project can be found on the Project menu. |
7 |
Run The menu items on the Run menu allow you to start a program in the run mode or debug mode. It also presents menu items that allow you to debug the code. |
8 |
Window The Window menu allows you to open and close views and perspectives. It also allows you to bring up the Preferences dialog. |
9 |
Help The Help menu can be used to bring up the Help window, Eclipse Marketplace view or Install new plug-ins. The about Eclipse menu item gives you version information. |
Customizing Menus
菜单上的可见菜单项取决于已安装的插件和使用 {s10} 对话框完成的自定义设置。
The visible menu items on a menu depend on the installed plug-ins and customization done using the Customize Perspective dialog box.
Eclipse - Explore Views
About Views
Eclipse 视图允许用户查看项目元数据的图形显示。例如,项目导航器视图提供与项目关联的文件夹和文件的图形显示,属性视图提供在另一个视图或编辑器中选定的元素的图形显示。
Eclipse views allow users to see a graphical representation of project metadata. For example the project navigator view presents a graphical representation of the folders and files associated with a project and properties view presents a graphical representation of an element selected in another view or editor.
Eclipse 透视图可以显示任意数量的视图和编辑器。所有编辑器实例显示在单个编辑器区域中,而视图置于视图文件夹中。工作台窗口可以显示任意数量的视图文件夹。每个视图文件夹可以显示一个或多个视图。
An eclipse perspective can show any number of views and editors. All editor instances appear in a single editor area, whereas views are placed inside view folders. A workbench window can display any number of view folders. Each view folder can display one or more views.
Organizing Views
下图显示了排列在一个视图文件夹中的四个视图。
The following picture shows four views arranged in a view folder.
下图显示了排列在两个视图文件夹中的相同四个视图。
The picture given below shows the same four views arranged in two view folders.
Moving Views
若要将视图从一个视图文件夹移动到另一个视图文件夹,只需单击视图标题并将该标题拖动到另一个视图文件夹的标题栏区域。下面显示的绿色线是将属性视图的标题栏从一个视图文件夹拖动到另一个视图文件夹标题栏区域的结果。属性视图可通过释放鼠标按钮并发出放置事件,移到绿色线所处的位置。
To move a view from one view folder to another, just click on the view title and drag to the title bar area of another view folder. The green line shown below is a result of dragging the title bar of the Properties view from one view folder to the title bar area of another view folder. The Properties view can be moved to where the green line is by releasing the mouse button and sending out a drop event.
Creating View Folders
拖动视图的标题栏到编辑器区域和另一视图文件夹的标题栏以外的任何位置,可以动态创建视图文件夹。当在四周拖动标题栏的时候,绿线会指示新视图文件夹的创建位置。
View folders can be dynamically created by dragging the title bar of a view to anywhere outside the editor area and title bar of another view folder. As you drag the title bar around, green lines will indicate where exactly the new view folder will be created.
将拖动图标移至窗口的底部,可以创建横跨窗口整个宽度的视图文件夹。将拖动图标移至窗口的左侧或右侧边缘,可以创建横跨窗口整个高度的视图文件夹。
Moving the drag icon to the bottom of a window allows you to create a view folder that spans the entire width of the window. Moving the drag icon to the left or right edge of window allows you to create a view folder that spans the entire height of the window.
Opening a view
要打开视图,请单击 Window 菜单并选择 Show View 菜单项。
To open a view, click on the Window menu and select the Show View menu item.
单击 Other 菜单项,将显示“显示视图”对话框,此对话框使您能够找到和激活某个视图。
Clicking on the Other menu item brings up the Show View dialog box that allows you to locate and activate a view.
视图按类别整理。只需在过滤器文本框中键入视图的名称,即可快速找到某个视图。要打开视图,请选中该视图并单击“确定”按钮。本教程的后续页面将介绍一些有用的视图。
The views are organized by category. To quickly locate a view just type the name of a view into the filter text box. To open a view, select it and click on the OK button. The subsequent pages of this tutorial introduce you to a number of useful views.
Eclipse - Perspectives
What is a Perspective?
Eclipse 透视图是指视图和编辑器区域的初始集合和排列。默认透视图称为 Java。一个 Eclipse 窗口可以同时打开多个透视图,但任何时刻只有一个透视图处于活动状态。用户可以在打开的透视图之间切换或打开一个新的透视图。活动透视图控制某些菜单和工具栏中显示的内容。
An eclipse perspective is the name given to an initial collection and arrangement of views and an editor area. The default perspective is called java. An eclipse window can have multiple perspectives open in it but only one perspective is active at any point of time. A user can switch between open perspectives or open a new perspective. The active perspective controls what appears in some menus and tool bars.
Opening a Perspective
要打开一个新的透视图,请单击“窗口”菜单,然后选择“打开透视图”→“其他”。
To open a new perspective, click on the Windows menu and select Open Perspective → Other
“打开透视图”对话框显示所有可用的透视图。通过单击工具栏上的“打开透视图”按钮 ( ),也可以打开相同的对话框。
The Open Perspective dialog box shows all the available perspectives. The same dialog can be brought up by clicking on the Open Perspective button ( ) on the tool bar.
Switching between Perspectives
Java 开发最常用的透视图是 Java 透视图和调试透视图。用户可以通过单击工具栏上的“透视图”名称在打开的透视图之间切换。
The most commonly used perspectives for java development are the Java perspective and Debug perspective. Users can switch between open perspectives by clicking on the Perspective name on the toolbar.
Closing a Perspective
要关闭某个透视图,请在工具栏中右击透视图名称,然后选择“关闭”菜单项。
To close a perspective, right click on the perspective name in toolbar and select the Close menu item.
Customizing a Perspective
“自定义透视图”对话框可以用来自定义透视图。对透视图进行自定义意味着:
The customize perspective dialog can be used to customize a perspective. Customizing a perspective means −
-
Determining the icons visible on the toolbar when a perspective is active.
-
Determining the menu items visible when a perspective is active.
-
Determine the menu items in New submenu, Show View submenu and Open Perspective submenu.
“自定义透视图”的选项卡说明如下:
The tab descriptions of customize perspective are given below −
-
The Tool Bar Visibility tab can be used to determine which icons are visible on the toolbar when a perspective is open.
-
The Menu Visibility tab can be used to determine which menu items are visible when a perspective is active.
-
The Command Groups Availability tab can be used to control the visibility of toolbar icons and menu items.
-
The Shortcuts tab can be used to determine the menu items in New submenu, Show View submenu and Open Perspective submenu.
根据下面图片中快捷方式的选择,为了打开“从现有 Ant 构建文件新建 Java 项目”向导,用户必须打开新建子菜单(文件 → 新建),单击其他,展开 Java 类别,然后选择“从现有 Ant 构建文件新建 Java 项目”。而另一方面,为了启动新建类向导,他们可以打开新建子菜单(文件 → 新建)并选择类菜单项,因为菜单项已在下面图片中选择。通过选中“从现有 Ant 构建文件新建 Java 项目”复选框,此项也将显示在新建菜单中。
Based on the Shortcuts selection in the picture given below, to bring up the "New Java Project from Existing Ant Build File" wizard users have to bring up the New submenu (File → New), click on Other, expand the Java category and then select "Java Project from Existing Ant Build File". On the other hand, to start the New Class wizard they can bring up the New submenu (File → New) and select the Class menu item because its selected in the picture given below. By selecting the "Java Project from Existing Ant Build File" check box this item will also appear under the New menu.
Eclipse - Workspaces
About Eclipse Workspace
Eclipse 工作区包含以下资源:
The eclipse workspace contains resources such as −
-
Projects
-
Files
-
Folders
工作区具有一个层次结构。项目是层次结构的顶层,在其中你可以拥有文件和文件夹。插件使用资源插件提供的 API 来管理工作区中的资源。
The workspace has a hierarchical structure. Projects are at the top level of the hierarchy and inside them you can have files and folders. Plug-ins use an API provided by the resources plug-in to manage the resources in the workspace.
UI Elements for Managing the Workspace
用户使用视图、编辑器和向导提供的功能来创建和管理工作区中的资源。显示工作区内容的众多视图之一是项目资源管理器视图。
Users use the functionality provided by views, editors and wizard to create and manage resources in the workspace. One among the many views that show the content of the workspace is the Project Explorer view.
文件向导(文件 → 新建 → 文件)可用来创建一个新文件。
The File Wizard (File → New → File) can be used to create a new file.
文件夹向导(文件 → 新建 → 文件夹)可用来创建一个新文件夹。
The Folder Wizard (File → New → Folder) can be used to create a new folder.
Eclipse - Create Java Project
Opening the New Java Project wizard
可以通过 New Java Project(新建 Java 项目)向导来创建新的 Java 项目。有多种打开此向导的方法:
The New Java Project wizard can be used to create a new java project. There are many ways to open this wizard −
-
By clicking on the File menu and choosing New →Java Project.
-
By right clicking anywhere in the Project Explorer and selecting New → Java Project.
-
By clicking on the New button ( ) in the Tool bar and selecting Java Project.
Using the New Java Project wizard
New Java Project(新建 Java 项目)向导有两个页面。在第一页上:
The New Java Project Wizard has two pages. On the first page −
-
Enter the Project Name
-
Select the Java Runtime Environment (JRE) or leave it at the default
-
Select the Project Layout which determines whether there would be a separate folder for the source codes and class files. The recommended option is to create separate folders for sources and class files.
您可以点击完成按钮来创建工程,也可以点击下一步按钮来更改 Java 构建设置。
You can click on the Finish button to create the project or click on the Next button to change the java build settings.
在第二页,您可以更改 Java Build Settings ,如设置工程依赖项(如果有多个工程)和向构建路径添加额外的 jar 文件。
On the second page you can change the Java Build Settings like setting the Project dependency (if there are multiple projects) and adding additional jar files to the build path.
Viewing the Newly Created Project
软件包浏览器显示新创建的 Java 工程。表示工程的图标带有 J 装饰,表示该工程是一个 Java 工程。文件夹图标带有装饰,表示该文件夹是一个 Java 源文件夹。
The package explorer shows the newly created Java project. The icon that represents a Project is decorated with a J to show that it is a Java Project. The folder icon is decorated to show that it is a java source folder.
Eclipse - Create Java Package
Opening the New Java Package wizard
你可以使用新建 Java 包向导创建一个 Java 包。Java 包向导可以用不同的方式打开:
You can use the New Java Package wizard to create a Java package. The Java Package wizard can be opened in different ways −
-
By clicking on the File menu and selecting New → Package.
-
By right click in the package explorer and selecting New → Package.
-
By clicking on the package icon which is in the tool bar( ).
如果您创建的是子软件包,请在打开 Java 软件包向导之前选择父软件包,以便 name 字段其中有默认值。
If you are creating a sub package, before opening the Java Package wizard select the parent package so that name field can have a default value in it.
Eclipse - Create Java Class
Opening the New Java Class Wizard
您可以使用新建 Java 类向导来创建 Java 类。可以通过多种方式调用 Java 类向导 -
You can use the New Java Class wizard to create a Java class. The Java Class wizard can be invoked in different ways −
-
By clicking on the File menu and selecting New → Class.
-
By right clicking in the package explorer and selecting New → Class.
-
By clicking on the class drop down button ( ) and selecting class ( ).
如果可能,请在启动新建 Java 类向导之前选择将创建类的软件包,以便向导可以自动填充软件包名称。
Before bringing up the New Java Class wizard, if possible, select the package in which the class is to be created so that the wizard can automatically fill in the package name for you.
Using the New Java Class Wizard
显示 java 类向导后 -
Once the java class wizard comes up −
-
Ensure the source folder and package are correct.
-
Enter the class name.
-
Select the appropriate class modifier.
-
Enter the super class name or click on the Browse button to search for an existing class.
-
Click on the Add button to select the interfaces implemented by this class.
-
Examine and modify the check boxes related to method stubs and comments.
-
Click the Finish button.
Eclipse - Create Java Interface
Opening the New Java Interface Wizard
可以使用“新建 Java 接口”向导新建 java 接口。有许多打开此向导的方法 −
The New Java Interface wizard can be used to create a new java interface. There are many ways of opening this wizard −
-
Clicking on the File menu and selecting New → Interface.
-
Right clicking in the package explorer and selecting New > Interface.
-
Clicking on the class drop down button () in the tool bar and selecting Interface ().
-
启动“新建 Java 接口”向导之前,如果可能,请选择要创建接口的包,以便向导可以自动为您填写包名。
Before bringing up the New Java Interface wizard, if possible, select the package in which the interface is to be created so that the wizard can automatically fill in the package name for you.
Using the New Java Interface Wizard
-
“java 接口”向导启动后 −
Once the java interface wizard comes up −
-
Ensure the source folder and package are correct.
-
Enter the interface name.
-
Click on the Add button to select the extended interfaces.
-
Select the Generate comments check box if you like comments to be generated.
-
Click on the Finish button.
Eclipse - Create XML File
Opening the New XML File wizard
-
您可以使用“新建 XML 文件”向导创建 XML 文件。要调用此向导 −
You can use the New XML file wizard to create an XML file. To invoke this wizard −
-
Click on the File menu and select New → Other or
-
Click on the new drop down box () select other or
-
Press ctrl + N
-
“选择向导”对话框出现后 −
Once the Select a wizard dialog box comes up −
-
In the filter text box enter xml, this should show only the wizards related to xml.
-
Expand XML category and select XML File.
-
Click on Next to bring up the New XML File wizard.
Using the New XML File wizard
新 XML 文件向导出现后,执行以下操作:
Once the New XML File wizard comes up −
-
Enter or select the parent folder.
-
Enter the name of the xml file.
-
Click on the Next button to base the xml file on DTD, XML Schema or XML template else click on Finish.
Viewing the Newly Created XML File
新创建的 XML 文件应出现在包资源管理器视图中,一个允许您修改新创建的 XML 文件的 XML 编辑器实例应出现在编辑器区域中。
The newly created XML file should appear in the Package Explorer view and an XML editor instance that allows you to modify the newly created XML file should appear in the editor area.
XML 编辑器允许您使用设计视图或代码视图编辑 XML 文件。
The XML editor allows you to edit an XML file using either the Design view or Source view.
Eclipse - Java Build Path
Setting the Java Build Path
在编译 Java 项目时使用 Java 构建路径来发现依赖类。它由以下项组成:
The Java build path is used while compiling a Java project to discover dependent classes . It is made up of the following items −
-
Code in the source folders.
-
Jars and classes folder associated with the project.
-
Classes and libraries exported by projects referenced by this project.
可以通过使用 Java 项目属性对话框的 Java 构建路径页查看和修改 Java 构建路径。
The java build path can be seen and modified by using the Java Build Path page of the Java Project properties dialog.
为了打开 Java 项目属性对话框,在程序包资源管理器视图中右键单击 Java 项目,并选择属性菜单项。在左侧树中选择 Java Build Path 。
To bring up the Java Project properties dialog box, right click on a Java Project in the Package Explorer view and select the Properties menu item. On the left hand side tree select Java Build Path.
在开发 Java 应用程序时看到的常见需求是向 Java 构建路径添加现有 JAR。这可以通过使用“库”选项卡完成。在“库”选项卡中,如果 JAR 已在 Eclipse 工作台中,只需单击 Add JARs ;如果 JAR 在文件系统的其他位置,则单击添加外部 JAR。
A common requirement seen while developing java applications is to add existing jars to the java build path. This can be accomplished using the Libraries tab. In the Libraries tab, just click on Add JARs if the jar is already in the Eclipse workspace or click on Add External JARs if the jar is elsewhere in the file system.
Eclipse - Run Configuration
Creating and Using a Run Configuration
运行配置对话框允许您创建多个运行配置。每个运行配置可以启动一个应用程序。通过从“运行”菜单中选择“运行配置”菜单项,可以调用“运行配置”对话框。
The Run Configurations dialog allows you create multiple run configurations. Each run configuration can start an application. The Run Configuration dialog can be invoked by selecting the Run Configurations menu item from the Run menu.
要为 Java 应用程序创建运行配置,请从左侧的列表中选择“Java 应用程序”,然后单击“新建”按钮。在出现的对话框中,在主选项卡中指定:
To create a run configuration for a Java application select Java Application from the list on the left hand side and click on the New button. In the dialog box that comes up in the main tab specify −
-
A name for the run configuration.
-
The name of a Project.
-
The name of the main class.
在参数选项卡中,指定:
In the arguments tab specify −
-
Zero or more program arguments.
-
Zero or more Virtual Machine arguments.
“常规”选项卡提供常规选项,例如分配一个控制台用于标准输入和输出的能力。
The Commons tab provides common options such as the ability to allocate a console for standard input and output.
要保存运行配置,请单击“应用”按钮,要启动应用程序,请单击“运行”按钮。
To save the run configuration click on the Apply button and to launch the application click on the Run button.
Eclipse - Running Program
Running a Java Program
运行 Java 程序的最快方法是使用包资源管理器视图。
The quickest way to run a Java program is by using the Package Explorer view.
在包资源管理器视图中:
In the Package Explorer view −
-
Right click on the java class that contains the main method.
-
Select Run As → Java Application.
还可以使用“包资源管理器”视图执行相同操作,方法是选择包含 main 方法的类并单击 Alt + Shift + X,J。
The same action can be performed using the Package Explorer view by selecting the class that contains the main method and clicking Alt + Shift + X, J.
上面提到的任一操作都会新建一个 Run Configuration 并使用它来启动 Java 应用程序。
Either actions mentioned above create a new Run Configuration and use it to start the Java application.
如果已创建运行配置,则可以选择“运行”菜单中的“运行配置”,单击运行配置的名称,然后单击“运行”按钮,以使用该配置启动 Java 应用程序。
If a Run configuration has already been created you can use it to start the Java application by selecting Run Configurations from the Run menu, clicking on the name of the run configuration and then clicking on the Run button.
可以从 Run 菜单使用 Run 项来重启之前启动的 Java 应用程序。
The Run item on the Run menu can be used to restart the java application that was previously started.
启动先前已启动的 Java 应用程序的快捷键是 Ctrl + F11。
The shortcut key to launch the previously launched Java application is Ctrl + F11.
Eclipse - Create Jar Files
Opening the Jar File wizard
可以利用 Jar 文件向导将项目的目录导出到 Jar 文件中。要打开 Jar 文件向导,请执行以下操作:
The Jar File wizard can be used to export the content of a project into a jar file. To bring up the Jar File wizard −
-
In the Package Explorer select the items that you want to export. If you want to export all the classes and resources in the project just select the project.
-
Click on the File menu and select Export.
-
In the filter text box of the first page of the export wizard type in JAR.
-
Under the Java category select JAR file.
-
Click on Next.
Using the Jar File wizard
在 JAR 文件规范页面中:
In the JAR File Specification page −
-
Enter the JAR file name and folder.
-
The default is to export only the classes. To export the source code also, click on the Export Java source files and resources check box.
-
Click on Next to change the JAR packaging options.
-
Click on Next to change the JAR Manifest specification.
-
Click on Finish.
Eclipse - Close Project
Why Close a Project?
一个 Eclipse 工作区可以包含任意数量的项目。一个项目可以是打开状态或关闭状态。
An eclipse workspace can contain any number of projects. A project can be either in the open state or closed state.
打开的项目:
Open projects −
-
Consume memory.
-
Take up build time especially when the Clean All Projects (Project → Clean all projects) with the Start a build immediately option is used.
How to Close a Project?
如果一个项目没在积极开发中,它会被关闭。要关闭项目,从项目中选择“关闭项目”菜单项。
If a project is not under active development it can be closed. To close a project, from the Project select the Close Project menu item.
Closed Project in Package Explorer
一个被关闭的项目会在包资源管理器视图中可见,但其内容不能使用 Eclipse 用户界面编辑。此外,一个打开的项目不能对一个关闭的项目有依赖。包资源管理器视图使用不同的图标来表示被关闭的项目。
A closed project is visible in the Package Explorer view but its contents cannot be edited using the Eclipse user interface. Also, an open project cannot have dependency on a closed project. The Package Explorer view uses a different icon to represent a closed project.
Eclipse - Reopen Project
Reopening a Closed Project
要重新打开关闭的项目,在“包资源管理器”视图中,选择关闭的项目并单击“项目”菜单,然后选择“打开项目”。
To reopen a closed project, in the Package Explorer view, select the closed project and click on the Project menu and select Open Project.
一旦项目打开,便可以使用 Eclipse 用户界面编辑其内容。
Once the project is open its content can be edited using the Eclipse user interface.
Eclipse - Build Project
Building a Java Project
一个项目可以有零个或更多关联的生成器。一个 Java 项目关联到一个 Java 生成器。要查看与项目关联的生成器 -
A project can have zero or more builders associated with it. A java project is associated with a java builder. To see the builders associated with a project −
-
In the Package Explorer view right click on the project and select Properties.
-
In the left hand side tree click Builders.
java 构建器区分了 Java 项目和其他类型的项目。通过单击新建按钮,可以将 Ant 构建器与 java 项目关联。java 构建器负责编译 java 源代码并生成类。
It’s the java builder that distinguishes a Java project from other types of projects. By click on the New button you can associate the Ant builder with a java project. The java builder is responsible for compiling the java source code and generating classes.
java 构建器会收到工作空间资源的更改通知,并可以自动编译 java 代码。要禁用自动编译,请从项目菜单中取消选择自动构建选项。
The java builder is notified of changes to the resources in a workspace and can automatically compile java code. To disable automatic compilation deselect the Build Automatically option from the Project menu.
如果禁用了自动编译,则可以通过选择项目菜单上的构建项目菜单项来明确地构建项目。如果选择了自动构建菜单项,则禁用构建项目菜单项。
If automatic compilation is disabled then you can explicitly build a project by selecting the Build Project menu item on the Project menu. The Build Project menu item is disabled if the Build Automatically menu item is selected.
Eclipse - Debug Configuration
Creating and Using a Debug Configuration
一个 Eclipse 调试配置类似于运行配置,但它用于在调试模式中启动应用程序。因为应用程序在调试模式中启动,所以会提示用户切换到调试透视图。调试透视图提供多种适合于调试应用程序的视图。
An eclipse debug configuration is similar to a run configuration but it used to start an application in the debug mode. Because the application is started in the debug mode the users are prompted to switch to the debug perspective. The debug perspective offers a number of views that are suitable for debugging applications.
通过从“运行”菜单中选择“调试配置”菜单项可以调用“调试配置”对话框。
The Debug Configuration dialog can be invoked by selecting the Debug Configurations menu item from the Run menu.
要为 Java 应用程序创建一个调试配置,从左侧列表中选择“Java 应用程序”,然后单击“新建”按钮。在弹出的对话框的主选项卡中指定 −
To create a debug configuration for a Java application, select Java Application from the list on the left hand side and click on the New button. In the dialog box that comes up in the main tab specify −
-
A name for the debug configuration.
-
The name of a Project.
-
The name of a main class.
在参数选项卡中,指定 −
In the arguments tab, specify −
-
Zero or more program arguments.
-
Zero or more Virtual Machine arguments.
要保存运行配置,请单击“应用”按钮,要以调试模式启动应用程序,请单击“调试”按钮。
To save the run configuration, click on the Apply button and to launch the application in the debug mode click on the Debug button.
Eclipse - Debugging Program
Debugging a Java Program
调试一个 Java 程序最快速的方法是使用包资源管理器视图。在包资源管理器视图 −
The quickest way to debug a Java program is to using the Package Explorer view. In the Package Explorer view −
-
Right click on the java class that contains the main method.
-
Select Debug As → Java Application.
可以通过使用包资源管理器选择包含主方法的类并单击 Alt+Shift+D、J 执行同样的操作。
The same action can be performed using the Package Explorer by selecting the class that contains the main method and clicking Alt + Shift + D, J.
上面提到的两个操作都会创建一个新的 Debug Configuration ,并使用它启动 Java 应用程序。
Either actions mentioned above create a new Debug Configuration and use it to start the Java application.
如果一个调试配置已经创建,你可以通过从“运行”菜单中选择“调试配置”,单击调试配置的名称,然后单击“调试”按钮来使用它启动 Java 应用程序。
If a Debug configuration has already been created you can use it to start the Java application by selecting Debug Configurations from the Run menu, clicking on the name of the debug configuration and then clicking on the Debug button.
“运行”菜单中的“调试”菜单项可用于重新启动先前在调试模式中启动的 Java 应用程序。
The Debug menu item on the Run menu can be used to restart the java application that was previously started in the debug mode.
以调试模式启动先前启动的 Java 应用程序的快捷键是 F11。当一个 Java 程序在调试模式中启动时,会提示用户切换到调试透视图。调试透视图提供了额外的视图,可用于对应用程序进行故障排除。
The shortcut key to launch the previously launched Java application in the debug mode is F11. When a java program is started in the debug mode, users are prompted to switch to the debug perspective. The debug perspective offers additional views that can be used to troubleshoot an application.
Java 编辑器允许用户在 Java 代码中放置断点。要设置一个断点,在编辑器区域右键单击标记栏并选择“切换断点”。
The java editor allows users to place break points in the java code. To set a break point, in the editor area right click on the marker bar and select Toggle Breakpoint.
断点显示在标记栏。它们也会在“断点”视图中可见。
Breakpoints are shown on the marker bar. They are also visible in the Breakpoints View.
当执行代码到达断点时,JVM 会暂停程序的执行。此时,你可以检查内存并在受控方式中执行程序。
When the execution of code reaches a break point the JVM suspends the execution of the program. At this point, you can inspect the memory and execute the program in a controlled manner.
当暂停程序执行时,可以利用调试视图来检查调用堆栈。
When the execution of a program is paused, the debug view can be used to inspect the call stack.
利用变量视图可以检查变量的值。
The variables view can be used to inspect the value of variables.
运行菜单有允许你恢复执行、跨越一行代码、进入函数等的菜单项。
The run menu has menu items that allow you to Resume execution, step over a line of code, step into a function etc.
上面给出的图片展示了与恢复、进入和跨越等动作关联的快捷键。
The picture given above shows the shortcut keys associated with actions such as Resume, Step Into and Step Over, etc.
Eclipse - Preferences
Setting Preferences
首选项对话框允许 Eclipse 用户管理他们的首选项。此对话框由框架管理,但是任何插件都可以在对话框中添加多个页面。
The Preferences dialog allows Eclipse users to manage their preferences. This dialog box is managed by the framework but any plug-in can add multiple pages to the dialog box.
要调用此对话框,请单击窗口菜单,并选择首选项菜单项。
To invoke this dialog, click on the Window menu and select the Preferences menu item.
首选项页面按类别组织。你可以通过展开对话框左侧树的节点找到首选项页面。
The preference pages are organized by category. You can locate a preference page by expanding the nodes of the tree in the left hand side of the dialog box.
左侧顶部角上的筛选文本框允许你快速找到一个首选项页面。当你向筛选文本框中输入字符时,左侧树中显示的项目会被筛选。例如,输入字体,可以快速进入字体首选项页面。
The filter text box on the left hand side top corner allows you to quickly locate a preference page. As you type characters into the filter text box the items shown in the left hand side tree are filtered. For e.g. type in font to quickly get to the Font preferences page.
在你对适当的首选项进行了更改后,单击 OK 按钮以保存更改并关闭对话框,或者单击 OK 按钮以放弃更改并关闭对话框。
After you make changes to the appropriate preferences click on the OK button to save the changes and close the dialog box or click on the Cancel button to discard the changes and close the dialog box.
Eclipse - Content Assist
Using Content Assist
在编辑器中,内容助手通过提供对已键入字符的可能完成的上下文相关的列表,帮助减少键入的字符。内容助手可以通过单击 Ctrl + 空格来调用。
Within an editor, content assist helps reduce the characters typed by providing a context sensitive list of possible completions to the characters already typed. The context assist can be invoked by clicking Ctrl + Space.
如果你正在 Java 编辑器中编辑方法的主体,并在新行中按下 Ctrl + 空格,它将弹出一个显示以下内容的对话框:
If you are editing the body of a method in the java editor and press Ctrl + Space on a new line it will bring up a dialog showing −
-
The class variables
-
The class methods
-
Super class methods
-
Other relevant classes
要从列表中选择一个项目,只需使用上或下箭头键高亮该项目并按回车键。
To select an item from the list just highlight the item using the up or down arrow keys and press enter.
如果你输入一些字符,然后按下 Ctrl + 空格,对话框将只显示以输入字符开头的项目。
If you type some characters and then press Ctrl + space the dialog box will show only items that start with the characters typed in.
Eclipse - Quick Fix
Using Quix Fix
当你向 Eclipse 编辑器输入字符时,它将分析文档内容以找出潜在的错误和警告。Java 编辑器使用 Java 语法来检测代码中的错误。当它发现错误或警告时,它将:
As you type characters into an eclipse editor it analyzes the document content for potential error and warnings. The java editor uses the java syntax to detect errors in the code. When it finds error or warning, it −
-
Highlights errors using red squiggly lines.
-
Highlights warnings using yellow squiggly lines.
-
Displays errors and warnings in the Problem view.
-
Adds a light bulb with a warning sign or error sign to the vertical ruler.
快速修复对话框提供可能的更正列表。可以通过以下方式调用快速修复对话框:
The quick fix dialog provides a list of possible corrections. The quick fix dialog can be invoked by −
-
Placing the mouse pointer on a squiggly line.
-
Clicking on the light bulb.
-
Placing the cursor in the highlighted text and selecting Quick fix from the Edit menu or clicking shortcut Ctrl + 1.
在上述图表中,getId 被突出显示,因为 Person 类没有名为 getId() 的方法。选择在类型“Person”中“创建方法”getId()“将导致 getId() 方法被添加到 Person 类。
In the above diagram, getId is highlighted because the Person class does not have a method called getId(). Selecting Create method 'getId()' in type 'Person' would cause the getId() method to be added to the Person class.
还可通过右键单击“问题”视图中的错误项目,然后选择“快速修复”菜单项来显示快速修复对话框。
The Quick Fix dialog can also be displayed by right clicking on the error item in the Problems view and selecting the Quick Fix menu item.
Eclipse - Hover Help
Using Hover Help
java 编辑器与不同类型的悬停相关。悬停提供有关鼠标指针下元素的附加信息。可通过 Java 编辑器悬停首选项页面查看与 java 编辑器相关的所有悬停。
The java editor is associated with different type of hovers. A hover provides additional information about the element under the mouse pointer. All the hovers associated with a java editor can be seen in the Java editor Hovers preference page.
在 java 编辑器中,将鼠标指针放在已导入的类上将显示与该类相关的 java doc。
In the java editor, placing the mouse pointer over the class being imported displays the java doc associated with that class.
将鼠标指针放在方法上将显示该方法的 java 文档。
Placing a mouse pointer on a method shows the java documentation for that method.
Eclipse - Search Menu
Searching the Workspace
借助 Eclipse 搜索对话框,您可以在整个工作区、一组工程、特定工程或软件包浏览器视图中选定的文件夹中搜索包含文字或字符模式的文件。
The Eclipse search dialog box allows you to search for files that contain a literal or a character pattern in the entire workspace, a set of projects, a specific project or folders selects in the package explorer view.
可以通过以下方式调用搜索对话框:
The search dialog box can be invoked by −
-
Clicking on the Search menu and selecting Search or File or Java.
-
Clicking Ctrl + H.
文件搜索页面允许您搜索任何类型文件,但 Java 搜索页面只关注 Java 文件。
The File Search page allows you to search any type of file but the Java Search page focuses on Java files only.
举例来说,要在 Java 搜索页面中搜索 Person 类型用法,请执行以下操作:
For example, to search for usage of the Person type, in the Java Search page −
-
Enter Person into the search box.
-
Set the Search For radio button to Type.
-
Set the Limit To radio button to References.
-
Click Search.
搜索结果显示在搜索视图中。
The search result appears in the Search View.
Eclipse - Navigation
Navigating the Eclipse Workspace
导航菜单提供许多可让您快速找到资源并导航到它的菜单项。
The navigate menu provides a number of menu items that allow you to quickly locate and navigate to a resource.
其中 Open Type、Open Type in Hierarchy 和 Open Resource 菜单项往往非常有用。
Among them, the Open Type, Open Type in Hierarchy and Open Resource menu items tend to be very useful.
Open Type
Open Type 菜单项会弹出一个对话框,可让您找到 Java 类型。在过滤器文本框中,输入类的完全限定名或名称。可以此字符代表 0 个或更多个字符和“?”代表单个字符来指定模式。对话框将显示所有与给定模式匹配的名称。
The Open Type menu item brings up a dialog box that allows you to locate a Java type. In the filter text box enter in either the fully qualified name or name of a class. The '*' character which stands for 0 or more characters and '?' which stands for a single character can be used to specify patterns. The dialog box will show all the names that match the given pattern.
选择您感兴趣的类型,然后单击 OK 。
Select the type you are interested in and click OK.
Eclipse 会打开一个显示所选类型的编辑器。如果所选类型的源代码不可用,它将使用类文件编辑器来显示所选类型的字节码。
Eclipse will open up an editor showing the selected type. If source code is not available for the selected type it will use the Class File editor to show the byte code of the selected type.
您可以使用“附加源”按钮来指定类的源代码所在位置。
You can use the Attach Source button to specify where the source code for the class is located.
java 发行版附带的类型的源代码位于 src.zip 中,该文件位于 java 主文件夹中。
The source code for the types that comes with the java distribution is in src.zip which is located in the java home folder.
Open Type in Hierarchy
Open Type in Hierarchy 菜单项允许您在类型层次结构视图中打开类型。可以此 Open Type in Hierarchy 对话框用于在构建路径中找到任何 Java 类型。
The Open Type in Hierarchy menu items allows you to open a type in the Type Hierarchy view. The Open Type in Hierarchy dialog box can be used to locate any Java type in the build path.
选择类型后,其层次结构将显示在类型层次结构视图中。
Once you select a type, its hierachy is shown in the Type Hierarchy view.
类型层次结构是学习类型层次结构的出色视图。在左侧窗格类型中,可使用其父类型和子类型。在右侧窗格中,您可以看到显示所选类型属性和方法。
The Type Hierarchy is an excellent view for learning about the hierarchy of a type. On the left hand side pane type, its super type and sub type are available. On the right hand side pane you can see the attributes and methods of a selected type are shown.
Open Resource
可以使用 open resource 菜单项来查找工作空间中的文件。可以此字符代表 0 个或更多个字符和“?”代表单个字符来指定模式。对话框将显示所有与给定模式匹配的名称。
The open resource menu item can be used to locate a file in the workspace. The '*' character which stands for 0 or more characters and '?' which stands for a single character can be used to specify patterns. The dialog box will show all the names that match the given pattern.
在编辑器中选择想要打开的文件,然后单击“确定”按钮。
Select the file that you want to open in an editor and click on the OK button.
Eclipse - Refactoring
Refactoring using Eclipse
重命名整个项目中广泛使用的类可能需要花费大量时间,但 Eclipse 重构向导通过自动检测对正在重命名的类的所有依赖关系并对其进行修改,使这项工作变得更加容易。
Renaming a class that is used widely throughout a project could take a lot of time but the Eclipse refactoring wizard makes the job easier by automatically detecting all dependencies on the class being renamed and modifying them also.
可以通过以下方式打开重构菜单:
The refactor menu can be opened by −
-
Right clicking on a Java element in the Package Explorer view and selecting Refactor menu item.
-
Right clicking on a Java element in the Java editor and selecting Refactor menu item.
-
Selecting a Java element in either the Package Explorer view or Java Editor and clicking Shift + Alt + T.
重构菜单显示对所选 Java 元素支持的所有可能的更改。要重命名类,请选择重命名菜单项。
The refactor menu shows all the possible changes that are supported on the selected Java element. To rename a class, select the Rename menu item.
单击下一步按钮以查看更改的预览(如果可用)。然后单击完成,让向导执行其工作。
Click on the Next button to see a preview of the changes (if available). Then click on Finish to get the wizard to do its work.
Eclipse - Add Bookmarks
About Bookmarks
Eclipse 编辑器允许您在编辑器内的任何行上放置书签名。您可以将书签用作提醒,并快速导航至文件中的任何行。
Eclipse editors allow you to place a book mark on any line within the editor. You can use bookmarks to serve as reminders and quickly navigate to any line in a file.
Adding a Bookmark
要设置书签,请右键单击您想要放置书签的行的垂直标尺附近,然后选择“添加书签”。在“添加书签”对话框中,输入书签的名称。
To set a bookmark, right-click on the vertical ruler near the line on which you want the bookmark and select Add Bookmark. In the Add Bookmark dialog box enter a name for the Bookmark.
书签图标会显示在垂直标尺中。此外,还会在“书签”视图的表格中添加一行。
A bookmark icon appears in the vertical ruler. Also, a row is added to the table in the Bookmarks view.
Opening the Bookmarks View
要打开“书签”视图−
To open the Bookmarks view −
-
Click on the Window menu and select Show View → Other.
-
In the filter text box enter Bookmark.
-
Under General, select Bookmarks.
-
Click on OK.
Using the Bookmarks View
“书签”视图会显示放在整个工作区中的资源中的书签。
The Bookmarks view shows bookmarks placed in resources across the workspace.
使用“书签”视图,可以通过双击某个书签或右键单击某个书签并选择菜单项“转到”来导航到该书签。
Using the Bookmarks view you can navigate to a bookmark by double clicking on a bookmark or right clicking on a bookmark and selecting "Go to" menu item.
Eclipse - Task Management
Managing Tasks
程序员喜欢在代码中放置 TODO 标记,作为需要完成的任务的提醒。Java 代码中包含单词 TODO 的注释被识别为任务,并且会显示在标记栏和“任务”视图中。
Programmers like to place TODO markers in their code which serves as a reminder for tasks that need to be completed. Comments in the Java code that has the word TODO in them are recognized as task and shown on the marker bar and in the Tasks view.
Eclipse 编辑器可用于将任务与正在编辑的文件关联,方法是右键单击标记栏并选择“添加任务”。在弹出的对话框中,输入任务描述,并从优先级下拉列表中选择一个优先级,然后单击“确定”按钮。
An eclipse editor can be used to associate tasks with the file being edited by right clicking on the marker bar and selecting Add Task. In the dialog box that comes up enter the task description and select a priority from the priority drop down list and then click on the OK button.
要使用 Eclipse 编辑器删除任务,请右键单击标记栏中的任务图标,然后选择菜单项“删除任务”。
To remove a task using an Eclipse editor, right-click on the task icon in the marker bar and select the Remove Task menu item.
Eclipse - Install Plugins
Locating and Installing Plug-ins
构成了 Eclipse IDE 基础的 Eclipse 平台由插件组成,并且设计为使用额外插件扩展。
The Eclipse platform which provides the foundation for the Eclipse IDE is composed of plug-ins and is designed to be extensible using additional plug-ins.
有几百个插件可用。每个插件都为 Eclipse 增加了更多功能。您可以通过搜索 Eclipse Market place ( http://marketplace.eclipse.org/ ) 来找到提供某些功能的插件。例如,您可以找到允许将 eclipse 用作 Python IDE 的插件。
Several hundreds of plug-ins are available. Each plug-in adds more functionality to Eclipse. You can locate a plug-in that provides certain functionality by searching the Eclipse Market place (http://marketplace.eclipse.org/). For example you can locate plug-ins that allows eclipse to be used as a Python IDE.
在 Eclipse IDE 中,您可以使用 Eclipse Marketplace 对话框搜索市场,可以通过单击“帮助”菜单并选择“Eclipse Marketplace”来调用此对话框。
From within the Eclipse IDE, you can search the market place by using the Eclipse Marketplace dialog which can be invoked by clicking on the Help menu and selecting Eclipse Marketplace.
在上面的屏幕截图中,要安装 PyDev-Python IDE for Eclipse,只需单击“安装”按钮即可。使用出现的对话框,您可以安装该插件。
In the screenshot above, to install PyDev-Python IDE for Eclipse, just click on the Install button. Using the dialog box that comes up you can install the plug-in.
您还可以使用“帮助”菜单中的“安装新软件”菜单项(“帮助”→“安装新软件”)来安装插件。
You can also install a plug-in by using the Install New Software menu item accessible from the Help menu (Help → Install New Software).
在这种情况下,您必须知道可以从中下载插件的远程站点的 URL。您可以通过单击“添加”按钮来提供此 URL。
In this case you have to know the URL of the remote site from which the plug-in can be downloaded. You can supply this URL by clicking on the Add button.
install 对话框显示了远程站点中可用的插件组件,并允许您安装它们。
The install dialog box shows the plug-in components available in the remote site and allows you to install them.
Eclipse - Code Templates
Using Code Templates
代码模板通过在编辑器中插入代码来帮助减少键入时间。每个代码模板都给定了一个简短的文字。在编辑器窗口中键入文字并按下 Ctrl + 空格键,会出现一个对话框,从中可以选择与此文字相关联的代码模板。
Code templates help reduce typing time by inserting code into the editor. Each code template is given a short literal. Typing the literal into the editor window and press Ctrl + Space brings up a dialog box from which a code template associated with that literal can be selected.
在 java 编辑器窗口中某个方法的主体中键入 for 并单击 Ctrl + 空格键会显示与 for 关联的代码模板。
Typing for within the body of a method in the java editor window and clicking Ctrl + space shows the code templates associated with for.
选择 for - 在数组上迭代会为 method 主体中早先声明的 depArray 遍历插入代码。
Selecting for - iterate over array inserts code for iterating through depArray which was declared earlier in the method body.
另一个有用的代码模板文字是 sysout ,它可用于插入 System.out.println() 方法调用。
Another useful code template literal is sysout which can be used to insert the System.out.println() method call.
Modifying/Adding code templates
您可以使用“首选项”对话框添加新的代码模板。通过单击“窗口”菜单并选择“首选项”菜单项,打开“首选项”对话框。要在“过滤器”文本框中找到“模板”页面,请键入“模板”。
You can add new code templates using the Preferences dialog box. Bring up the Preferences dialog box by clicking on the Windows menu and selecting the Preferences menu item. To locate the Templates page type Templates into the filter text box.
您可以通过阅读 Eclipse 帮助来了解有关可用于自定义所插入代码的变量的更多信息。要打开帮助窗口,请单击“帮助”菜单并选择“帮助内容”。在搜索文本框中输入 Java Editor Template Variables。在左侧列表中选择 Java Editor Template Variables。
You can read more about the variables that can be used to customize the code that is inserted by reading the Eclipse help. To bring up the help window click on the Help menu and select Help Contents. In the search text box enter Java Editor Template Variables. From the list on the left hand side select Java Editor Template Variables.
Eclipse - Shortcuts
About Shortcuts
您可以仅使用键盘通过以下方法导航 Eclipse 用户界面 -
You can navigate the Eclipse User Interface using only the keyboard by −
-
Using mnemonics associated with menus and menu items.
-
Using mnemonics associated with controls in a dialog box or view or editor.
-
Using accelerators associated with actions such as menu items and buttons on the toolbar.
可以通过单击 Ctrl + Shift + L 来调用的“键帮助”操作向我们展示了 Eclipse 中的所有可用的加速器或快捷键。
The Key Assist action which can be invoked by clicking Ctrl + Shift + L shows us all the accelerators or shortcut keys available in Eclipse.
可以利用“键”首选项页面来更改分配给某个操作的键组合。Eclipse 中有许多没有快捷键的命令或操作。此首选项页面还允许您将快捷键分配给这些操作。
The key combination assigned to an action can be changed using the Keys preference page. There are many commands or actions in Eclipse for which there are no shortcut keys. This preference page also allows you to assign shortcut keys to these actions.
例如,要将 Alt + C 分配为触发带来 New Class 对话框的命令的快捷键,请在命令列表中选择 New Class ,导航到 Bindings 文本框,然后按 Alt + C. 下拉列表可以让你选择快捷键有效的上下文。确保所选键组合没有冲突,然后单击 确定 按钮。
For example, to assign Alt + C as the shortcut key to trigger the command that brings up the New Class dialog box select New Class in the command list, navigate to the Bindings text box and then press Alt + C. The when dropdown list allows you to select a context in which the shortcut key is valid. Ensure that there are no conflicts for the selected key combination and click on the OK button.
你现在可以按 Alt + C 来调出新类向导。
Now you can press Alt + C to bring up the New Class wizard.
Eclipse - Restart Option
Restarting Eclipse
重新启动选项允许用户重新启动 Eclipse。要重新启动 Eclipse,请单击文件菜单并选择 Restart 菜单项。
The restart option allows users to restart eclipse. To restart eclipse, click on the File menu and select the Restart menu item.
在安装插件后,会提示用户重新启动 Eclipse。如果他们选择在该时间点不要重新启动,他们可以在以后使用重新启动选项来重新启动 Eclipse。如果 Eclipse 用户界面出现故障,用户可能需要使用此选项重新启动 Eclipse。
After a plug-in is installed, users will be prompted to restart eclipse. If they choose not to restart at that point they can restart eclipse later by using the restart option. If eclipse user interface misbehaves, users may want to restart eclipse using this option.
Eclipse - Tips & Tricks
TIP #1 − DISCOVERING SHORTCUT KEYS
TIP #1 − DISCOVERING SHORTCUT KEYS
-
Press Ctrl + Shift + L to open a widget that shows all the shortcut keys.
TIP #2 − CONTENT ASSIST
TIP #2 − CONTENT ASSIST
-
In the Java editor press Ctrl + Space to see a list of suggested completions. Typing one or more characters before clicking Ctrl + Space will shorten the list.
TIP #3 − PARAMETER HINT
TIP #3 − PARAMETER HINT
-
When the cursor is in a method argument, press Ctrl + Shift + Space to see a list of parameter hints.
TIP #4 − CAMEL CASE SUPPORT IN CODE COMPLETION
TIP #4 − CAMEL CASE SUPPORT IN CODE COMPLETION
-
Code completion supports camel case patterns. Entering NPE and clicking Ctrl + Space will propose NullPointerException and NoPermissionException.
TIP #5 − CREATING GETTERS AND SETTERS
TIP #5 − CREATING GETTERS AND SETTERS
-
Click on Source → Generate Getter and Setter to open the wizard that allows you to generate getter and setter methods.
TIP #6 − GENERATING HASHCODE() AND EQUALS() METHODS
TIP #6 − GENERATING HASHCODE() AND EQUALS() METHODS
-
Click on Source → Generate hashCode() and equals() to generate this methods for a Java class.
TIP #7 − ADDING CODE AROUND A BLOCK OF CODE
TIP #7 − ADDING CODE AROUND A BLOCK OF CODE
-
Select a block of code and press Alt+Shift+Z to see a menu of items like if statement, for loop, try/catch etc that can enclose the selected block of code.
TIP #8 − LOCATING A MATCHING BRACKET
TIP #8 − LOCATING A MATCHING BRACKET
-
Select an opening or closing bracket and press Ctrl+Shift+P to find its matching bracket.
TIP #9 − SMART JAVADOC
TIP #9 − SMART JAVADOC
-
Type '/**' and press Enter to automatically addes a Javadoc comment stub.
TIP #10 − ORGANIZAING IMPORTS
TIP #10 − ORGANIZAING IMPORTS
-
Press Ctrl+Shift+O to organize all the imports.
TIP #11 − ACTIVATING THE MENU BAR
TIP #11 − ACTIVATING THE MENU BAR
-
Press F10 to activate the Menu bar.
TIP #12 − MAKING A VIEW/EDITOR ACTIVE
TIP #12 − MAKING A VIEW/EDITOR ACTIVE
-
Press Ctrl+F7 to see a list of open views and editor area and switch to one of them.
Eclipse - Web Browsers
Internal Web Browser
“内部 Web 浏览器”视图允许您在 Eclipse Workbench 窗口内浏览互联网。若要激活“内部 Web 浏览器”视图,单击“窗口”,然后选择“显示视图”→“其他”。
The Internal Web Browser view allows you to surf the internet from within the Eclipse Workbench Window. To activate the Internal Web Browser view click on the Window and select Show View → Other.
在“显示视图”对话框的筛选文本框中,输入浏览器。从树中选择“内部 Web 浏览器”,然后单击 OK 。
In the filter text box of the Show View dialog box enter browser. From the tree select Internal Web Browser and click OK.
若要导航到一个网页,在“内部 Web 浏览器”视图的 URL 文本框中输入该网页的 URL。
To navigate to a web page, in the URL text box of the Internal Web Browser view enter a URL for that web page.