简体   繁体   中英

Java: Unresolved compilation problem

What are the possible causes of a "java.lang.Error: Unresolved compilation problem"?

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.

I would expect to see LinkageErrors or ClassNotFound errors if interfaces changed. The above error hints at some lower level problem.

A clean rebuild and redeployment fixed the problem. Could this error indicate a corrupted JAR?

(rewritten 2015-07-28)

This is possible as Eclipse uses its own built-in compiler, instead of javac<\/code> from the JDK which Apache Maven uses, and which fails the compilation completely for errors. If you use Eclipse on a Maven project which you are also working with using the command line mvn<\/code> command, this may happen.

尝试清理eclipse项目

you just try to clean maven by command

mvn clean

Your compiled classes may need to be recompiled from the source with the new jars.

Try running "mvn clean" and then rebuild

The major part is correctly answered by Thorbjørn Ravn Andersen.

The most likely cause for silently getting class files with errors into a jar is by concurrent operation of Maven and Eclipse.

There is no doubt that Eclipse found an error at compile time<\/em> .

Or, an automatic Eclipse build could react to changes in the filesystem (done by Maven) and re-compile a class, before<\/em> Maven proceeds to collect class files into the jar ( this is what I meant by "concurrent operation" in my original answer<\/em> ).

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.

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.

"

  1. Just try to include package name in eclipse in case if you forgot it
  2. Import all packages before using it, EX: import java.util.Scanner before using Scanner class .
  3. These improvements might work and it will not give Java: Unresolved compilation problem anymore.
  4. Also make sure to check compiler compliance level and selected jdk version is same

As a weird case, I encountered such an exception where the exception message (unresolved compilation bla bla) was hardcoded inside of generated class' itself. Decompiling the class revealed this.

"

I had the same issue using the visual studio Code. The root cause was backup java file was left in the same directory.

Removed the backup java file When the build failed, selected the Fix it, it cleaned up the cache and restarted the workSpace.

确保您已从构建路径中删除不可用的库(jar 文件)

"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM