无法在 Eclipse-Java 中编译/运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22133654/
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
Can't compile/run in Eclipse- Java
提问by Jess Anastasio
I'm trying to compile and run a simple program in Eclipse and whenever I hit run it says select what to run: and theres the option of two ant builds I have no clue what ant builds are or what to do about that.. when i try to run with the ant build it says "build failed: could not find an ant file to run" I have the newest version of java and everything should be working fine but when I can never get past the ant build problem.
我正在尝试在 Eclipse 中编译和运行一个简单的程序,每当我点击运行时,它都会说选择要运行的内容:并且有两个 ant 构建的选项,我不知道 ant 构建是什么或对此做什么..我尝试使用 ant 构建运行,它说“构建失败:找不到要运行的 ant 文件”我有最新版本的 java,一切都应该正常工作,但是当我永远无法解决 ant 构建问题时。
Thanks for any advice!
感谢您的任何建议!
回答by Hugo Kerstens
First make sure that you made a regular "Java Project", and not something else.
首先确保您创建了一个常规的“Java 项目”,而不是其他内容。
If there's something wrong with the build configuration, which i guess there is, go to: Run > Run Configurations... On the left you will see a list of configurations, make sure your configuration runs as a "Java Application". If not, delete all the configurations by selecting them and then press delete.
如果构建配置有问题,我猜是有问题,请转到:运行 > 运行配置...在左侧,您将看到配置列表,确保您的配置作为“Java 应用程序”运行。如果没有,请通过选择它们来删除所有配置,然后按删除。
If things are fine, your program should run normally
如果一切正常,您的程序应该可以正常运行
回答by Marco Roda
Create a Java Project by menu: File > New > Java Project
Only the Project name is mandatory (if needed, you can configure all other options later).Browse to your new project, and select the src folder.
New > Package
New > Class
Make sure to select the checkbox to create: public static void main(...) This creates a runnable class.Put some sample code to main(), e.g.:
System.out.println("HALLO");
Select the class in Package Explorer and Run As > Java Application
通过菜单创建 Java 项目:文件 > 新建 > Java 项目
只有项目名称是必需的(如果需要,您可以稍后配置所有其他选项)。浏览到您的新项目,然后选择 src 文件夹。
新建 > 包
New > Class
确保选中要创建的复选框: public static void main(...) 这将创建一个可运行的类。将一些示例代码放在 main() 中,例如:
System.out.println("你好");
在 Package Explorer 和 Run As > Java Application 中选择类
回答by Kohei Mikami
Add buildCommand
and nature
tags in your .project
file. You have to add Java Nature if you execute your project as Java project. Run As...
menus are decided from the natures.
在您的文件中添加buildCommand
和nature
标记.project
。如果您将项目作为 Java 项目执行,则必须添加 Java Nature。Run As...
菜单是根据性质决定的。
<projectDescription>
...
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>