Eclipse“运行方式”没有“Java 应用程序”选项(运行类/.java 到底需要什么?)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17114756/
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
Eclipse "Run as" has no "Java Application" option (What exactly is needed to be able to run a class/.java?)
提问by A.M.
I want to run a specific .java file (a class), but Eclipse is not co-operating.
我想运行一个特定的 .java 文件(一个类),但 Eclipse 不合作。
I have tried to follow the instructions here --> eclipse how to run a different class
我试图按照这里的说明进行操作 --> eclipse 如何运行不同的类
... but my "Run As" menu item never contains "Java Project".
...但我的“运行方式”菜单项从不包含“Java 项目”。
I have tried accessing the menu after right-clicking in the .java pane and tab itself, and from the .java name and class name in the Package Explorer, but of course that doesn't make a difference. The only option I ever get is "Run Configurations".
我尝试在 .java 窗格和选项卡本身中右键单击后访问菜单,并从包资源管理器中的 .java 名称和类名访问菜单,但这当然没有区别。我得到的唯一选项是“运行配置”。
(and yes, my .java has a "main" method.)
(是的,我的 .java 有一个“main”方法。)
import com.jsyn.JSyn;
public class SuperSimpleSounds {
public static void main() {
[...]
What, exactly, is needed to be able to run an individual class (an individual .java file)?
究竟需要什么才能运行单个类(单个 .java 文件)?
回答by Reimeus
Add a String
array argument to the main
method as expected by the JVM
按预期String
向main
方法添加数组参数JVM
public static void main(String[] args) {
回答by Great Question
Also one trick when you want to open some java classes that you downloaded elsewhere is to create a new Java project. Then, move all your java classes into the src folder of the project. Now you can run with the option of "run as Java Application".
当您想打开在别处下载的某些 Java 类时,另一个技巧是创建一个新的 Java 项目。然后,将所有 java 类移动到项目的 src 文件夹中。现在您可以使用“作为 Java 应用程序运行”选项运行。
回答by Arif Mirza
As a minor variation on the perfect answerof Reimus:
Add a
String
array argument to themain
method as expected by theJVM
public static void main(String[] args) {
按预期
String
向main
方法添加数组参数JVM
public static void main(String[] args) {
I had been struggling with my a script, when I ran it showed Run Configuration and Fail.
By changing the following:
我一直在为我的脚本苦苦挣扎,当我运行它时,它显示了运行配置和失败。
通过更改以下内容:
public static void LaunchBrowser () throws InterruptedException {
to
到
public static void main(String[] args) throws InterruptedException {
it solved the problem.
它解决了这个问题。