maven "cannot find symbol" message unhelpful
JavaMavenCompiler ErrorsSettingsJava Problem Overview
This is a really simple question, and it's probably a setting somewhere I don't know about, but Google is being particularly unhelpful for this question, giving results about compilation errors, not how to change compilation error messages.
When I build my project with maven, it will give me error messages formatted roughly as follows:
[ERROR] /path/to/source/Main.java:[13,8] error: cannot find symbol
When I build with ant or javac, it will actually tell me the symbol that it can't find in the error message. maven gives me a line number and character position, but displaying the actual symbol would be more helpful. The line above is the only line given for each of the "cannot find symbol" errors. There is no line above or below that gives the symbol. I imagine there has to be some way to get maven to tell me that information, but I don't know what it is. I tried the -e option, as mvn told me to try using it, but it gave a maven traceback for the error, not the actual symbol.
Any help?
Here's the output of mvn --version
Apache Maven 3.0.4 (rNON-CANONICAL_2012-10-24_11-25_mockbuild; 2012-10-24 07:25:04-0400)
Maven home: /usr/share/maven
Java version: 1.7.0_09-icedtea, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.6.6-1.fc17.x86_64", arch: "amd64", family: "unix"
And here's an example (unhelpful) error message, exactly as output by maven (just with directories shortened):
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /path/to/source/SoundEngineFilePanel.java:[33,8] error: cannot find symbol
[ERROR] class SoundEngineFilePanel
/path/to/source/SoundEngineFilePanel.java:[36,8] error: cannot find symbol
[INFO] 2 errors
[INFO] -------------------------------------------------------------
The symbols it can't find are "fakeThing" and "fakeThing2", not SoundEngineFilePanel.
Java Solutions
Solution 1 - Java
This is a bug in the Maven compiler plugin, related to JDK7 I think. Works fine with JDK6.
Solution 2 - Java
update to 3.1 :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Solution 3 - Java
In my case the problem was in a child jar which was not rebuilt since I have added a new class, pom.xml of that child jar was not related to my failed pom.xml as child-to-parent relation (using <parent>
tag). So I rebuilt the child jar after which the error had gone.
Solution 4 - Java
I had the same problem. The reason was that I had two JAR files were not added through the Maven dependency, so when I ran mvn compile
, the console display the error error:
> Symbol cannot be found,Class...".
To fix it:
- Remove the JAR files from build path
- Add to build path
- Run
mvn compile
Solution 5 - Java
In my case, I was using a dependency scoped as <scope>test</scope>
. This made the class available at development time but, by at compile time, I got this message.
Turn the class scope for <scope>provided</scope>
solved the problem.
Solution 6 - Java
This occurs because of this issue also i.e repackaging which you defined in POM file.
Remove this from pom file under maven plugin. It will work
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
Solution 7 - Java
Even I am using Java 7, maven 2.2.1 and was getting the same error, I removed <scope>tests</scope>
from my pom and used
mvn clean -DskipTests=true install
to successfully build my projects, without upgrading my maven version.
Solution 8 - Java
if you are having dependency on some other project in work space and these projects are not build properly, such error might come. try building such dependent projects first, it may help
Solution 9 - Java
If you are using Intellij and the above solutions are not working try: File > Invalidate Caches / Restart
This worked for me. Sometimes when you are working through multiple branches, the IDE uses its cache and cannot find the file in the cache hence it shows error during compilation.
Solution 10 - Java
This is not a function of Maven; it's a function of the compiler. Look closely; the information you're looking for is most likely in the following line.
Solution 11 - Java
SOLUTION: @Before building your component (using mvn clean install). Build the entire project once and build your component again
WHY SO :
I get this error many times.
Most of the times I will try to build my component alone (As I have not made changes elsewhere).
Right, But that extra jar which has been downloaded recently might have affected by changes done by a third party(inside their component). Making a full mvn clean install on entire project saved me many times
Solution 12 - Java
I got this error. To resolve this On the Project -> BuildPath -> TestNG I had to uncheck the 'Use project TestNG jar' Apply and Close. On the next run of 'mvn compile', the build was successful.
Solution 13 - Java
My guess the compiler is complaining about an invalid annotation. I've noticed that Eclipse doesnt show all errors, like a comma at the end of an array in a annotation. But the standard javac
does.
Solution 14 - Java
I was getting a similar problem in Eclipse STS when trying to run a Maven install on a project. I had changed some versions in the dependencies of my pom.xml file for that project and the projects that those dependencies pointed to. I solved it by running a Maven install on all the projects I changed and then running install on the original one again.
Solution 15 - Java
I had the same issue with maven. It happens that my problem was, maven was generating the folders with differenc case names. I was expecting a .service.MyFile but in the target folder it was Service/MyFile and java is a case sensitive. It took me a few hours to find out, recommend you to check it out.
Solution 16 - Java
Generally, this error will appear when your compile code's version is different from your written code's. For example, write code that rely on xxx-1.0.0.jar that one class has method A, but the method changed to B in xxx-1.1.0.jar. If you compile code with xxx-1.1.0.jar, you will see the error.
Solution 17 - Java
Perhaps you should check your IDE case sensitive properties. I had the same problem, and solved it by making Idea case-sensitive (for my filesystem is case sensitive): https://confluence.jetbrains.com/display/IDEADEV/Filesystem+Case-Sensitivity+Mismatch