Maven can't find symbol error


What's inside this article ⌄
  • Maven cannot find symbol error
  • Maven compilation symbol error
  • Maven symbol not found fix
  • Maven compile error cannot find

Suppose you have a class with constants Constants.java:

package org.example;

public class Constants {
    // ...
    public static final String MY_CONSTANT = "value";   
}

And you made the static import of this constant in another class MyOtherClass.java:

package org.example;

import static org.example.Constants.MY_CONSTANT;

public class MyOtherClass {
    // ...
}

Everything looks good, and IDEA does not show any mistakes (in fact, there are really no errors in code). But Maven suddenly failed building project with cannot find symbol error.

This situation can arise because there are too many constants declared in the original Constants class.

If you change this static import in the MyOtherClass.java class this way:

import static org.exampe.Constants.*;

The error should be gone.