maven “cannot find symbol” message unhelpful
maven “cannot find symbol” message unhelpful
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.
...and some more of the error output. I'm fairly sure the missing symbol is mentioned in the previous or next line!
– Anders R. Bystrup
Jan 4 '13 at 20:26
More information provided.
– mattg
Jan 4 '13 at 20:34
Add a code snippet please (the line around the error)
– asgoth
Jan 4 '13 at 20:57
Are you running a multithreaded build? (using
-T on the command line, or in your settings)– Isaac
Jan 4 '13 at 21:13
-T
13 Answers
13
This is a bug in the Maven compiler plugin, related to JDK7 I think. Works fine with JDK6.
Seems to be fixed in maven-compiler-plugin 3.1. See george-papatheodorou's answer.
– Jared Beck
Oct 27 '13 at 1:45
This is not a solution .. the compilation error is still happening in java 8.
– Eta
Nov 15 '17 at 9:06
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>
What is the best way to determine the latest version of this plugin? All I could find is this page: maven.apache.org/plugins/maven-compiler-plugin/… Thanks.
– Jared Beck
Oct 27 '13 at 1:42
maven.apache.org/plugins/index.html
– George Papatheodorou
Nov 5 '13 at 13:20
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>
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:
mvn compile
Symbol cannot be found,Class...".
To fix it:
mvn compile
Could you please list down the steps that you used to remove the JAR files from your build path? As I am getting the same error when I try to delete my target folder and recompile using maven? Thanks
– turnip424
May 31 at 9:54
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.
<parent>
This was my problem as well. While there are certainly existing bugs in Maven, I would expect that in most cases, Maven errors or build issues are explained by scenarios such as these.
– Michael M
May 10 '17 at 22:39
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
<scope>tests</scope>
mvn clean -DskipTests=true install to successfully build my projects, without upgrading my maven version.
mvn clean -DskipTests=true install
"mvn clean -DskipTests=true" install is a magic command ! Thx for sharing. (BTW I didn't touched my <scope>tests</scope>)
– Eta
Nov 15 '17 at 9:27
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.
Nope, that's not it. I edited the question.
– mattg
Jan 4 '13 at 20:30
I was getting the same error. The subsequent error gave the name of a dependency that was missing from the project (in this case an org.apache.poi.xssf library class).
– John
Jun 28 '17 at 17:43
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.
javac
The line that it's complaining about is
fakeThing = new JPanel(). It's just a standard "cannot find symbol" error that javac would show "fakeThing" for. maven just isn't showing it.– mattg
Jan 4 '13 at 20:55
fakeThing = new JPanel()
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.
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: @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
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
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.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you provide some version information (Maven in particular) etc? This isn't what happens for me.
– Dave Newton
Jan 4 '13 at 20:25