如何在 Eclipse 中创建默认调试和运行配置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2078733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create default debug and run configuration in Eclipse?
提问by Nikola Smiljani?
Whenever I hit Debug or Run in Eclipse, I get a dialog asking me what configuration I want to use.
每当我在 Eclipse 中点击 Debug 或 Run 时,都会出现一个对话框,询问我想使用什么配置。
How do I set a default configuration and bind a keyboard shortcut?
如何设置默认配置并绑定键盘快捷键?
回答by nanda
Maybe this article from Eclipse One Tipswill help you:
也许来自 Eclipse One Tips 的这篇文章会帮助你:
How to run the last launched application
The answer lies in a preference hidden on the Run/Debug page:
- Go to Window > Preferences > Run/Debug > Launching.
- Select the option Always launch the previously launched application. It's located at the bottom of the dialog.
The preference should look something like this:
Now you're free to press F11, Ctrl+F11or click the Run/Debug icons on the toolbar with confidence, knowing it's going to run what you expect it to run.
One question arises: How do you quickly run a class as a specific application (eg. a JUnit test) if you can't press F11to run it? You have some options available:
- The fastest way is to use keyboard shortcuts. Eclipse allows you to launch classes using a keystroke, including JUnit tests, Java applications, etc using Alt+Shift+X.
- Alternatively, right-click on the class and select Run As. The submenu will show available options for launching the class.
- Lastly, you could click the pulldown arrow on the run/debug icons in the toolbar and select Run As. The submenu once again shows available options for launching the class.
如何运行上次启动的应用程序
答案在于运行/调试页面上隐藏的首选项:
- 转到Window > Preferences > Run/Debug > Launching。
- 选择选项始终启动之前启动的应用程序。它位于对话框的底部。
首选项应如下所示:
现在,您可以放心地按 F11、Ctrl+F11或单击工具栏上的“运行/调试”图标,因为您知道它将按照您期望的方式运行。
一个问题出现了:如果您不能按下F11运行它,您如何将类作为特定应用程序(例如 JUnit 测试)快速运行?您有一些选择:
- 最快的方法是使用键盘快捷键。Eclipse允许你使用一个按键,包括JUnit测试,Java应用程序等使用,推出类Alt+ Shift+ X。
- 或者,右键单击该类并选择运行方式。子菜单将显示启动课程的可用选项。
- 最后,您可以单击工具栏中运行/调试图标上的下拉箭头,然后选择Run As。子菜单再次显示启动课程的可用选项。
回答by Faron
Eclipse plug-ins that add new project types may contribute 'Launch Configurations' to control how Eclipse executes the application. For example, J2EE based projects need to publish content and start the application server. Contrast this with simply starting a JVM for a regular Java application.
添加新项目类型的 Eclipse 插件可以提供“启动配置”来控制 Eclipse 如何执行应用程序。例如,基于 J2EE 的项目需要发布内容并启动应用服务器。将此与简单地为常规 Java 应用程序启动 JVM 进行对比。
When you select a configuration, Eclipse records this for future use. You can access these by selecting the 'Run/Run Configurations' menu item or selecting 'Run Configurations' from the little drop down menu next to the run and debug toolbar buttons. You can also add new launch configurations through the Run/Debug Configurations dialog that opens. In this dialog, you should see one or more configurations that you previously launched. Selecting one reveals all the info Eclipse uses to launch your application. One tab called 'Common' contains options for controlling the your favorites menu. Checking the box next to Run or Debug will add this launch configuration to the top of its corresponding menu.
当您选择配置时,Eclipse 会记录下来以备将来使用。您可以通过选择“运行/运行配置”菜单项或从运行和调试工具栏按钮旁边的小下拉菜单中选择“运行配置”来访问这些。您还可以通过打开的运行/调试配置对话框添加新的启动配置。在此对话框中,您应该会看到您之前启动的一个或多个配置。选择一个将显示 Eclipse 用于启动应用程序的所有信息。一个名为“Common”的选项卡包含用于控制收藏夹菜单的选项。选中 Run 或 Debug 旁边的框会将此启动配置添加到其相应菜单的顶部。
If you only have a single configuration in your menu then Eclipse will launch it when you click the associated button. If you have more than one then Eclipse launches (sometimes) the most recently used. I say sometimes because, occasionally, one launch configuration causes another to launch, which cause the last used configuration to be the second one when you would expect it to be the first one. Usually this happens to me when I launch an application, which needs to be built and the build launches a tool. When this happens, just select the correct launch configuration from the drop down menu.
如果您的菜单中只有一个配置,那么 Eclipse 将在您单击相关按钮时启动它。如果您有多个,那么 Eclipse 将启动(有时)最近使用的。我说有时是因为,有时一个启动配置会导致另一个启动,这会导致最后使用的配置成为第二个,而您希望它是第一个。通常,当我启动一个需要构建的应用程序并且构建启动一个工具时,会发生这种情况。发生这种情况时,只需从下拉菜单中选择正确的启动配置即可。
You can bind a keystroke combination to the Run and Debug commands through the 'Windows/Preferences' menu item. Then select 'General/Keys' in the tree control on the left.
您可以通过“Windows/Preferences”菜单项将按键组合绑定到“运行”和“调试”命令。然后在左侧的树控件中选择“General/Keys”。