【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方法的图标。

    Outline view with selected TestRunner class

  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 菜单。

    Run context menu

  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程序只能使用默认设置,不能指定参数。

    Console with error message: Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class

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

    Run menu of the toolbar

    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等其他选项。

    Launch configuration dialog showing the Main tab

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

    Arguments tab of the launch configuration dialog

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

    Console showing program output

  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首选页中修改。

    Debug view showing two terminated run launches

    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 按钮右边的下拉菜单,这里会显示曾经运行过的程序列表,点击可以重新运行。

    Run drop down menu from the workbench toolbar

  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首选页中修改该配置。

    Debug view showing two terminated run launches

  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 菜单清空启动记录,或者使用等价的快捷工具栏按钮
     

    Debug view showing context menu

转载于:https://my.oschina.net/ywlaker/blog/476753

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值