I have a Maven project with the following directory layout:
.
└── src
├── main
│ └── ...
└── test
└── java
└── com.foo
├── stubs
│ └── JsonSnippets.java
├── bar
│ └── BarTest.java
└── ... further tests
The JsonSnippets
class looks like this:
package com.foo.stubs;
public class JsonSnippets {
public final static String SNIPPET_A = "{...}";
}
Within the BarTest
class, I want to use the JsonSnippets
class, therefore I have
package com.foo.bar;
import com.foo.stubs.JsonSnippets;
// ...
@Test
public void testWithJsonSnippets() {
String json = JsonSnippets.SNIPPET_A;
// ...
}
When I now run mvn test
, I get the following error message:
cannot find symbol
[ERROR] symbol: class JsonSnippets
[ERROR] location: package com.foo.bar
Remark everything works as expected, when I put the JsonSnippets
class into the src/main/...
package / directory.
Problem was a broken Maven configuration in the project's directory. After I removed all non-project related cache files and created the project "from scratch" (with exactly the same sources), everything worked as described in my question.