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)
Summary: Eclipse had compiled some or all of the classes, and its compiler is more tolerant of errors.
Long explanation:
The default behavior of Eclipse when compiling code with errors in it, is to generate byte code throwing the exception you see, allowing the program to be run. This is possible as Eclipse uses its own built-in compiler, instead of javac 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 command, this may happen.
The cure is to fix the errors and recompile, before running again.
The setting is marked with a red box in this screendump:
try to clean the eclipse project
you just try to clean maven by command
mvn clean
and after that following command
mvn eclipse:clean eclipse:eclipse
and rebuild your project....
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.
This answer tries to shed light on the remaining question: how could the class file with errors end up in the jar?
Each build (Maven & 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.
If you have Eclipse open while running a mvn build, you should disable Project > Build Automatically until mvn completes.
EDIT:
Let's try to split the riddle into three parts:
(1) What is the meaning of "java.lang.Error: Unresolved compilation
problem"
This has been explained by Thorbjørn Ravn Andersen. There is no doubt that Eclipse found an error at compile time.
(2) How can an eclipse-compiled class file end up in jar file created
by maven (assuming maven is not configured to used ecj for
compilation)?
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, before Maven proceeds to collect class files into the jar (this is what I meant by "concurrent operation" in my original answer).
(3) How come there is a compile error, but mvn clean succeeds?
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.
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.
Just try to include package name in eclipse in case if you forgot it
Import all packages before using it, EX: import java.util.Scanner before using Scanner class.
These improvements might work and it will not give Java: Unresolved compilation problem anymore.
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.
I already changed the below items since I saw this-https://stackoverflow.com/questions/57299606/testng-by-default-disables-loading-dtd-from-unsecure-urls
Run/Debug configurations both class&method in both TESTNG and TESTNG Template vm option: -ea -Dtestng.dtd.http=true
testng.xml, and even I deleted the first line and follow the error message to put <!DECOTYPE ..... to the first line, it still failed
I still encounter this error.
Could anyone please help with this, please?
The external library was not completed.
After adding the "libs" folder under selenium-java-3.141.59 with okhttp-3.11.0.jar and okio-1.14.0.jar, it worked fine!
You don't really need to add -Dtestng.dtd.http=true if you are going to create your own testng.xml file with https for IntelliJ Run/Debug Configurations to use. You were seeing the error message because IntelliJ did not use your testng.xml file. By default IntelliJ generates a .xml file for TestNG configurations, which has a path like this C:/User/<your name>/AppData/Local/JetBrains/IntelliJIdea2020.2/temp-testng-customsuite.xml. You however cannot overwrite it because it is regenerated every time a TestNG configuration runs. IntelliJ's TestNG plugin is currently unable to dynamically generate the .xml with correct protocol, i.e. http vs https because of the concern for backward compatibility. Please see this commit for more details.
To use your own testng.xml, you need to change the Test kind of your TestNG configuration to Suite, then put/select the path of your testng.xml to be the value of Suite and apply. This answer also illustrates the above steps with images.
Last but not least, although the wording of the TestNG warning is strong, it is unlikely to be the cause of the NoClassDefFoundError in your screenshot. Maybe this is the answer for fixing that NoClassDefFoundError.
I encountered the following issue. I have four Cucumber feature files in IntelliJ. I added the Cucumber support via the IntelliJ plugin. After creating my features I edited my configuration like followed so i can execute the feature files.
Glue should be the name of the package the step definitions reside in. In my case the package is called stepdefinitions.
The following image shows what my project structure looks like. The feature files reside in /src/test/resource/features while the stepdefinitions are stored in /src/test/java/stepdefinitions.
Sadly when I try to run the cucumber features with the step definitions I get prompted "You can implement missing steps with the snippets below:" But I already did this. I already copied those snippets to the step definition files. When I hover a scenario IntelliJ tells me *Unimplemented Substep Definition".
Those two things lead me to the conclusion that IntelliJ does not find my step definitions. Maybe one of you knows what I am doing wrong.
I finally found the solution to my question. The error was caused by a plugin called Substep IntelliJ Plugin. You need to search for it in the IntelliJ Plugin Section and disable or deinstall it.
Try 'Invalidate cache and restart'. It worked for me - something the plugin gets stuck.
Disable the Cucumber plugin to avoid collisions over feature file association, install the Substeps plugin. See http://substeps.github.io/ for more docs on how to use the Substeps BDD framework alongside downloading a sample starter project from here: https://github.com/Substeps/substeps-example/archive/1.1.zip
Hello all I am trying to run a programme using Intellij. The programme runs perfectly in Eclipse and Terminal. However using IDEA it seems to ignore 2 files.
java.io.FileNotFoundException: .\data\def\items\ItemValues.txt (The system cannot find the path specified)
There are no errors normally in Intellij. I just get this error upon running it. The file is there I have checked and path is correct. Intellij just seems to be ignoring it.
Check Working directory in Run/Debug Configuration, you need to change it to $MODULE_DIR$ if you have multiple levels of maven modules.
I am working on a Java project. I am using IntelliJ Idea 12.1.4 as IDE.
I verify the quality of code two ways,
I have installed QAPlug-FindBugs plugin in IntelliJ idea and I analyze the code using
a custom analysis profile. This profile has only one findbugs rule activated.
I have applied findbugs plugin in build.gradle file of the project. I
run gradlew check command.
These two approaches result into different number of findbugs warnings/errors. Actually, gradlew check results into lot more errors/warnings than QAPlug -> Analyze Code.
I understand that when I mention apply plugin : 'findbugs' the effort level is set to Default value.
I tried to figure out the relation between gradle plugin and Intellij Idea plugin. I am not able to figure out what coding rules should be activated in my custom profile (for QAPlug -> Analyze Code action) to match the behavior of 'gradle check'.
Can anybody give me a pointer as to what's going on?
Vijay,
I am not sure if you are looking for information about QAPlug or Gradle.
In case of QAPlug please check following tutorial:
Creating your own analysis profile
Regarding the Gradle, I found the following information:
"By default, all detectors which are not disabled by default are run."
Gradle FindBugsExtension
To have the same number of Findbugs warnings/errors you should do the following:
deactivate all rules in you custom QAPlug analysis profile
using search box find those "Powered by Findbugs" and activate them
I hope that it helps.