Eclipse 不会将 java 文件编译为类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18010749/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 21:46:34  来源:igfitidea点击:

Eclipse doesn't compile java files into classes

javaeclipse

提问by Marco Micheli

I have no idea why, but from today Eclipse doesn't compile .java files into .class. I press the "Run" button and Eclipse only tries to run the program rather then compiles it first, so i get this error all the time:

我不知道为什么,但从今天起 Eclipse 不会将 .java 文件编译成 .class。我按下“运行”按钮,Eclipse 只尝试运行程序而不是先编译它,所以我一直收到这个错误:

Exception in thread "main" java.lang.NoClassDefFoundError

采纳答案by Marco Micheli

This problem happens when "for some reasons" your project is corrupted and has a red icon near the project's name in Eclipse. The solution is to save the project's folder, delete the project in Eclipse, than create the project again in Eclipse coping all the previous files saved.

当“出于某种原因”您的项目已损坏并且在 Eclipse 中项目名称附近有一个红色图标时,就会发生此问题。解决办法是保存项目的文件夹,在Eclipse中删除项目,然后在Eclipse中重新创建项目,覆盖之前保存的所有文件。

回答by Stimpson Cat

Do clean all projects ! This will erase all old class files, so eclipse is forced to generate them again.

清理所有项目!这将删除所有旧的类文件,因此 eclipse 被迫再次生成它们。

回答by Septem

open problems view from window -> show view -> problems, if there's any error, fix it

从窗口打开问题视图 -> 显示视图 -> 问题,如果有任何错误,请修复它

eclipse will reject to compile if there is any problems in your project

如果您的项目有任何问题,eclipse 将拒绝编译

回答by Vasanth Raj

Some times jars in the build path might be missing even though we are not using it. Since error is there, java files wont compile into classes. Can check errors from problems view.

有时,即使我们没有使用它,构建路径中的 jars 也可能会丢失。由于存在错误,java 文件不会编译为类。可以从问题视图检查错误。

Either remove jars from build path or place the missing jars in the build path.

从构建路径中删除 jars 或将缺少的 jars 放在构建路径中。

回答by nimesh makwana

There would be the case : if you have opened project explorer in eclipse then it may not show you classes generated under /**/build/classes, in such case open Navigator view of that project and check build directory under the same project.

会出现这种情况:如果您在 eclipse 中打开了项目资源管理器,那么它可能不会显示在 /**/build/classes 下生成的类,在这种情况下,打开该项目的导航器视图并检查同一项目下的构建目录。

回答by jan.supol

The eclipse needs to erase the output folder when building classes.

eclipse在构建类时需要擦除输出文件夹。

The folder is found on Project Properties -> Java Build Path -> Default Output Folder. It can differ from general output folder name found under Eclipse Preferences. If this output folder cannot be erased for some reason (for instance, on Windows, when a shell is opened on this location), the project is marked as corrupted (as Marco Micheli describes) and the classes then are not built.

该文件夹位于 上Project Properties -> Java Build Path -> Default Output Folder。它可能与 Eclipse 首选项下的一般输出文件夹名称不同。如果由于某种原因无法删除此输出文件夹(例如,在 Windows 上,在此位置打开外壳程序时),则项目将被标记为已损坏(如 Marco Micheli 所述),然后不会构建类。

You just need to make sure the output folder can be erased.

您只需要确保可以删除输出文件夹。

回答by StrangeLoop

I ran into this problem with Eclipse Luna, for some reason the Java builder was missing from the project. Verify that in your .project file you have something like

我在使用 Eclipse Luna 时遇到了这个问题,由于某种原因,项目中缺少 Java 构建器。验证您的 .project 文件中是否有类似的内容

<buildSpec>
    <buildCommand>
        <name>org.eclipse.jdt.core.javabuilder</name>
        <arguments>
        </arguments>
    </buildCommand>     
</buildSpec>

You can also configure builders from Project Properties -> Builders

您还可以从 Project Properties -> Builders 配置构建器

回答by Johnny2012

Close Project -> Open Project -> Clean -> Refresh

关闭项目 -> 打开项目 -> 清理 -> 刷新

Hope it helps for someone else

希望对其他人有帮助

回答by Aarish Ramesh

Also ensure that there are no projects with fatal errors (projects with ! symbol over it) in the build path of the project which is not generating classes under the bin directory

还要确保在 bin 目录下未生成类的项目的构建路径中没有出现致命错误的项目(带有 ! 符号的项目)

回答by Harpal

  1. there can be errors in your project, or other reasons like mentioned in above answers.
  2. or you may be a fool like me
  1. 您的项目中可能存在错误,或上述答案中提到的其他原因。
  2. 否则你可能像我一样傻

who moved the source code to other folder and not updated source path in project build properties. in this case it was not giving any error or class files too. check that too.

谁将源代码移动到其他文件夹,而不是在项目构建属性中更新源路径。在这种情况下,它也没有给出任何错误或类文件。也检查一下。

goto Project Properties -> Java Build Path -> Source

转到项目属性 -> Java 构建路径 -> 源代码

Add or Link new source folder location.

添加或链接新的源文件夹位置。