Maven clean install: cannot find symbol
Solution 1
Found the problem...
I apologize as I didn't include enough code for anyone to determine the root cause of the issue, normally I don't include import statements in my posts but this time I should have. The below class is a more full example. As we can see, the below class declares a static import to an object that resides in the static nested class (within the same .java file). While this is not illegal from a compilation standpoint, it was causing issues in my Maven clean install. I'm still not %100 sure why maven does not like this, but this fashion of static importing doesn't really make sense to begin with. To fix this, I removed the static import and substituded a normal static call (MyAnnoation.someObject) wherever the static import was being used.
package com.classes;
import static com.classes.MyClass.MyAnnotation.someObject;
public class MyClass{
@MyAnnotation
public static class MyAnnotation{
public static final Object someObject = new Object();
}
Again, my apologies for not providing the static import details in my original post, hopefully someone finds this helpful.
Solution 2
Did your maven-compiler-plugin
is using 1.5. By default it used 1.4 and annotations are introduced in 1.5
Jason
Professional software developer of 6+ years and programming enthusiast.
Updated on July 09, 2022Comments
-
Jason almost 2 years
My Maven clean install is failing. Below is the error message.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project MyProject: Compilation failure: Compilation failure: [ERROR] C:\..\MyClass.java:[13,2] cannot find symbol [ERROR] symbol : class MyAnnotation [ERROR] location: class mypackage.MyClass
MyClass.java
public class MyClass{ @MyAnnotation public static class MyAnnotation{ //some static nested class code here... }
MyAnnotation.java
@Retention (RetentionPolicy.RUNTIME) public @interface MyAnnotation{ }
I have no clue why this would present problems, can anyone please give me some ideas?