Java:未解决的编译问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1124788/
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
Java: Unresolved compilation problem
提问by
What are the possible causes of a "java.lang.Error: Unresolved compilation problem"?
“java.lang.Error:未解决的编译问题”的可能原因是什么?
Additional information:
附加信息:
I have seen this after copying a set of updated JAR files from a build on top of the existing JARs and restarting the application. The JARs are built using a Maven build process.
在从现有 JAR 之上的构建复制一组更新的 JAR 文件并重新启动应用程序后,我已经看到了这一点。JAR 是使用 Maven 构建过程构建的。
I would expect to see LinkageErrors or ClassNotFound errors if interfaces changed. The above error hints at some lower level problem.
如果接口更改,我希望看到 LinkageErrors 或 ClassNotFound 错误。上述错误暗示了一些较低级别的问题。
A clean rebuild and redeployment fixed the problem. Could this error indicate a corrupted JAR?
干净的重建和重新部署解决了这个问题。此错误是否表示 JAR 损坏?
回答by Thorbj?rn Ravn Andersen
(rewritten 2015-07-28)
(改写 2015-07-28)
The default behavior of Eclipse when compiling code with errors in it, is to generate byte code throwing the exception you see. This is possible as Eclipse uses its own built-in compiler, instead of javac
from the JDK which Apache Maven uses. If you use Eclipse on a Maven project which you are also working with using the command line mvn
command, this may happen.
当编译有错误的代码时,Eclipse 的默认行为是生成字节码并抛出您看到的异常。这是可能的,因为 Eclipse 使用它自己的内置编译器,而不是javac
来自 Apache Maven 使用的 JDK。如果您在 Maven 项目上使用 Eclipse,并且您也在使用命令行mvn
命令处理该项目,则可能会发生这种情况。
The cure is to fix the errors and recompile, before running again.
解决方法是在再次运行之前修复错误并重新编译。
The setting is marked with a red box in this screendump:
该设置在此屏幕转储中用红色框标记:
回答by Steve Pearson
Your compiled classes may need to be recompiled from the source with the new jars.
您编译的类可能需要使用新的 jar 从源代码重新编译。
Try running "mvn clean" and then rebuild
尝试运行“mvn clean”然后重建
回答by micahli123
try to clean the eclipse project
尝试清理eclipse项目
回答by jaideep
you just try to clean maven by command
您只需尝试通过命令清理 maven
mvn clean
and after that following command
然后执行以下命令
mvn eclipse:clean eclipse:eclipse
and rebuild your project....
并重建您的项目....
回答by djb
I had this error when I used a launch configuration that had an invalid classpath. In my case, I had a project that initially used Maven and thus a launch configuration had a Maven classpath element in it. I had later changed the project to use Gradle and removed the Maven classpath from the project's classpath, but the launch configuration still used it. I got this error trying to run it. Cleaning and rebuilding the project did not resolve this error. Instead, edit the launch configuration, remove the project classpath element, then add the project back to the User Entries in the classpath.
当我使用具有无效类路径的启动配置时,我遇到了这个错误。就我而言,我有一个最初使用 Maven 的项目,因此启动配置中包含一个 Maven 类路径元素。后来我将项目更改为使用 Gradle 并从项目的类路径中删除了 Maven 类路径,但启动配置仍然使用它。我在尝试运行它时遇到此错误。清理和重建项目没有解决这个错误。相反,编辑启动配置,删除项目类路径元素,然后将项目添加回类路径中的用户条目。
回答by Vinh
I got this error multiple times and struggled to work out. Finally, I removed the run configuration and re-added the default entries. It worked beautifully.
我多次遇到此错误并努力解决。最后,我删除了运行配置并重新添加了默认条目。它工作得很好。
回答by Stephan Herrmann
The major part is correctly answered by Thorbj?rn Ravn Andersen.
Thorbj?rn Ravn Andersen 正确回答了主要部分。
This answer tries to shed light on the remaining question: how could the class file with errors end up in the jar?
这个答案试图阐明剩下的问题:有错误的类文件如何最终出现在 jar 中?
Each build (mvn&javac or eclipse) signals in its specific way when it hits a compile error, and will refuse to create a Jar file from it (or at least prominently alert you). The most likely cause for silently getting class files with errors into a jar is by concurrent operation of Maven and Eclipse.
每个构建(mvn&javac 或 eclipse)在遇到编译错误时都以其特定的方式发出信号,并且将拒绝从中创建 Jar 文件(或至少显着地提醒您)。以静默方式将有错误的类文件放入 jar 的最可能原因是 Maven 和 Eclipse 的并发操作。
If you have Eclipse open while running a mvn build, you should disableProject> Build Automaticallyuntil mvn completes.
如果您在运行 mvn 构建时打开了 Eclipse,您应该禁用Project> Build Automatically,直到 mvn 完成。
EDIT: Let's try to split the riddle into three parts:
编辑:让我们尝试将谜语分成三个部分:
(1) What is the meaning of "java.lang.Error: Unresolved compilation problem"
(1) “java.lang.Error: Unresolved compiler problem”是什么意思
This has been explained by Thorbj?rn Ravn Andersen. There is no doubt that Eclipse found an error at compile time.
Thorbj?rn Ravn Andersen 对此进行了解释。毫无疑问,Eclipse在编译时发现了错误。
(2) How can an eclipse-compiled class file end up in jar file created by maven (assuming maven is notconfigured to used ecj for compilation)?
(2)eclipse编译的class文件怎么会出现在maven创建的jar文件中(假设maven没有配置为使用ecj进行编译)?
This could happen either by invoking maven with no or incomplete cleaning. Or, an automatic Eclipse build could react to changes in the filesystem (done by maven) and re-compile a class, beforemaven proceeds to collect class files into the jar (this is what I meant by "concurrent operation" in my original answer).
这可能通过调用 Maven 而不进行清理或不完全清理来实现。或者,自动 Eclipse 构建可以对文件系统中的更改(由 maven 完成)做出反应并重新编译一个类,然后maven 继续将类文件收集到 jar 中(这就是我在原始答案中所说的“并发操作”的意思)。
(3) How come there is a compile error, but
mvn clean
succeeds?
(3) 怎么会出现编译错误,但是
mvn clean
成功了?
Again several possibilities: (a) compilers don't agree whether or not the source code is legal, or (b) Eclipse compiles with broken settings like incomplete classpath, wrong Java compliance etc. Either way a sequence of refresh and clean build in Eclipse should surface the problem.
还有几种可能性:(a) 编译器不同意源代码是否合法,或者 (b) Eclipse 使用损坏的设置进行编译,例如不完整的类路径、错误的 Java 合规性等。无论哪种方式,都在 Eclipse 中进行一系列的刷新和清理构建问题应该浮出水面。
回答by user1729564
Make sure you have removed unavailable libraries (jar files) from build path
确保您已从构建路径中删除不可用的库(jar 文件)