Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 614
mattg Avatar asked Jan 04 '13 20:01

mattg


People also ask

Can not find symbol maven?

A “Cannot find symbol” error means that the compiler cannot do this. Your code appears to be referring to something that the compiler doesn't understand. When your code is compiled, the compiler needs to work out what each and every identifier in your code means.

What does Cannot find symbol mean in Java?

The cannot find symbol error, also found under the names of symbol not found and cannot resolve symbol , is a Java compile-time error which emerges whenever there is an identifier in the source code which the compiler is unable to work out what it refers to.

What is Maven build command?

mvn clean: Cleans the project and removes all files generated by the previous build. mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code. mvn test: Runs tests for the project.


2 Answers

This is a bug in the Maven compiler plugin, related to JDK7 I think. Works fine with JDK6.

like image 143
Peter Svensson Avatar answered Oct 06 '22 08:10

Peter Svensson


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> 
like image 30
George Papatheodorou Avatar answered Oct 06 '22 08:10

George Papatheodorou