【Eclipse】使用指南(19)运行程序

(翻译说明:http://my.oschina.net/ywlaker/blog/468911)

Running your programs

运行程序

In this section, you will learn more about running Java programs in the workbench.

本小节,你将学会更多与在工作台中运行Java程序有关的知识。

  1. In the Package Explorer view, find junit.textui/TestRunner.java and double-click it to open it in an editor.
    在包管理器视图中双击junit.textui/TestRunner.java文件打开。
  2. In the Outline view, notice that the TestRunner class has an icon which indicates that the class defines amainmethod.
    在Outline视图中,注意到TestRunner 类有一个标示其拥有main方法的图标。

    【Eclipse】使用指南(19)运行程序_第1张图片

  3. Right click on TestRunner.java in the Package Explorer and select Run As > Java Application. This will launch the selected class as a local Java application. The Run As context menu item is also available in other places, such as the Outline view.
    在包管理器视图中右键TestRunner.java 选择Run As > Java Application菜单,该类将以本地Java应用程序的方式启动。同样,可以在Outline视图或编辑器中右键选择Run As 菜单。

    【Eclipse】使用指南(19)运行程序_第2张图片

  4. Notice that the program has finished running and the following message appears in the Console view telling you that the program needs an execution argument.  Running class from the Package Explorer as a Java Application uses the default settings for launching the selected class and does not allow you to specify any arguments.
    注意到程序运行结束了,但Console 视图告诉你程序缺少执行参数。从包管理器中运行Java程序只能使用默认设置,不能指定参数。

    【Eclipse】使用指南(19)运行程序_第3张图片

  5. To specify arguments, use the drop-down Run menu in the toolbar and select Run Configurations....
    使用工具栏中的Run 菜单并选择Run Configurations…可以指定运行的参数。

    【Eclipse】使用指南(19)运行程序_第4张图片

    You can also Ctrl+Click a configuration in the drop-down menu to start editing that configuration.

  6. This time, the Launch Configurations dialog opens with the TestRunner launch configuration selected. A launch configuration allows you to configure how a program is launched, including its arguments, classpath, and other options.  (A default launch configuration was created for you when you choseRun > Java Application).
    启动配置对话框打开(需要手动双击Java Application才会出现右边的各种输入框),在这里可以设置启动的参数、classpath等其他选项。

    【Eclipse】使用指南(19)运行程序_第5张图片

  7. Select the Arguments tab and type junit.samples.VectorTest in the Program arguments area.
    选择Arguments 选项卡,然后在Program arguments 区域输入junit.samples.VectorTest

    【Eclipse】使用指南(19)运行程序_第6张图片

  8. Click Run. This time the program runs correctly, indicating the number of tests that were run.
    这一次,程序运行正确,Console视图显示了运行的测试用例。

    【Eclipse】使用指南(19)运行程序_第7张图片

  9. Switch to the Debug perspective. In the Debug view, notice that a process for the last program launch was registered when the program was run.

    By default, the Debug view automatically removes any terminated launches when a new launch is created. This preference can be configured on the Run/Debug > Launching preference page
    切换至Debug视图,注意到有程序最后一次运行信息显示在这里。默认情况下,在Debug视图中知会显示程序最后一次运行的情况,之前的记录被覆盖。该设置可以在Run/Debug > Launching首选页中修改。

    【Eclipse】使用指南(19)运行程序_第8张图片

    Note: You can relaunch a terminated process by selecting Relaunch from its context menu.
    注意:在Debug视图中可以右键程序选择Relaunch 重新运行。

  10. Select the drop-down menu from the Run button in the workbench toolbar. This list contains the previously launched programs. These programs can be relaunched by selecting them in the history list.
    选择工具栏Run 按钮右边的下拉菜单,这里会显示曾经运行过的程序列表,点击可以重新运行。

    【Eclipse】使用指南(19)运行程序_第9张图片

  11. By default the currently selected resource or active editor is launched when the run button is hit. If none of these is launchable the current project will be launched. You can configure this behavior under Run/Debug > Launching.
    默认当你点击运行按钮时,会启动选择的源文件或者激活的编辑器中的内容,如果他们都不能启动,将启动当前工程。可以在Run/Debug > Launching首选页中修改该配置。

    【Eclipse】使用指南(19)运行程序_第10张图片

  12. From the context menu in the Debug view (or the equivalent toolbar button), select Remove All Terminated to clear the view of terminated launch processes.
    在Debug视图中右键选择Remove All Terminated 菜单清空启动记录,或者使用等价的快捷工具栏按钮
     

    【Eclipse】使用指南(19)运行程序_第11张图片

你可能感兴趣的:(java,eclipse,debug,application,run)