Eclipse 不会编译/运行 java 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21068440/
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 won't compile/run java file
提问by Jess Anastasio
I am just trying to compile and run a simple java program. When I go to run my tester class it says select what to run and it gives me Ant Build which when highlighted says "Launches an Ant build with default settings" or Ant Build... that says "Launches an Ant build and allows it to be configured". When I try to select either of these it prompts Build failed. Reason: Unable to find ant file to run. I honestly don't know what these ant builds and files are. This is definitely a dumb question but have no idea what to do.
我只是想编译和运行一个简单的 java 程序。当我去运行我的测试程序类时,它说选择要运行的内容,它给我 Ant Build,突出显示时说“使用默认设置启动 Ant 构建”或 Ant Build... 说“启动 Ant 构建并允许它进行配置”。当我尝试选择其中任何一个时,它会提示构建失败。原因:无法找到要运行的 ant 文件。老实说,我不知道这些 ant 构建和文件是什么。这绝对是一个愚蠢的问题,但不知道该怎么做。
回答by Guy Gavriely
right click somewhere on the file or in project explorer and choose 'run as'->'java application'
右键单击文件或项目资源管理器中的某处,然后选择“运行方式”->“java 应用程序”
回答by BrianC
Your project has to have a builder set for it. If there is not one Eclipse will default to Ant. Which you can use you have to create an Ant build file, which you can Google how to do. It is rather involved though. This is not required to run locally in Eclipse though. If your class is run-able. It looks like yours is, but we can not see all of it.
您的项目必须为其设置一个构建器。如果没有一个 Eclipse 将默认为 Ant。您可以使用它创建一个 Ant 构建文件,您可以谷歌如何做。虽然它相当复杂。不过,这不是在 Eclipse 中本地运行所必需的。如果您的课程可以运行。它看起来像你的,但我们不能看到它的全部。
If you look at your project build path do you have an output folder selected? If you check that folder have the compiled class files been put there? If not the something is not set in Eclpise for it to know to compile. You might check to see if auto build is set for your project.
如果您查看项目构建路径,是否选择了输出文件夹?如果您检查该文件夹是否已将编译的类文件放在那里?如果不是,则 Eclpise 中未设置某些内容以供编译。您可以检查是否为您的项目设置了自动构建。
回答by Calvin
- Make a project to put the files in.
- File -> New -> Java Project
- Make note of where that project was created (where your "workspace" is)
- Move your java files into the
src
folderwhich is immediately inside the project's folder.- Find the project INSIDE Eclipse's Package Explorer (Window -> Show View -> Package Explorer)
- Double-click on the project, then double-click on the 'src' folder, and finally double-click on one of the java files inside the 'src' folder (they should look familiar!)
- Now you can run the files as expected.
- 创建一个项目来放置文件。
- 文件 -> 新建 -> Java 项目
- 记下该项目的创建位置(您的“工作区”在哪里)
- 将你的java文件到
src
文件夹中,并立即开始项目的文件夹内。- 在 Eclipse 的 Package Explorer 中找到项目(Window -> Show View -> Package Explorer)
- 双击项目,然后双击“src”文件夹,最后双击“src”文件夹中的其中一个java文件(它们应该看起来很熟悉!)
- 现在您可以按预期运行文件。
Note the hollow 'J' in the image. That indicates that the file is not part of a project.
请注意图像中的空心“J”。这表明该文件不是项目的一部分。
回答by 89n3ur0n
I was also in the same problem, check your build path in eclipse by Right Click on Project> build path> configure build path
我也遇到了同样的问题,通过右键单击项目>构建路径>配置构建路径,在 Eclipse 中检查您的构建路径
Now check for Excluded Files, it should not have your file specified there by any means or by regex.
现在检查排除的文件,它不应该以任何方式或通过正则表达式在那里指定您的文件。
Cheers!
干杯!
回答by Ninad Pingale
This worked for me:
这对我有用:
- Create a new project
- Create a class in it
- Add erroneous code, let error come
- Now go to your project
- Go to Problems window
- Double click on a error
- 创建一个新项目
- 在其中创建一个类
- 添加错误代码,让错误来了
- 现在去你的项目
- 转到问题窗口
- 双击错误
It starts showing compilation errors in the code.
它开始在代码中显示编译错误。