1

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.

Michael Lihs
  • 7,460
  • 17
  • 52
  • 85

2 Answers2

0

Check if you have imported the JsonSnippet class properly or not.

Check if JsonSnippet class has public constructor defined.

Sumit Kumar
  • 375
  • 1
  • 11
  • 1
    I guess `import com.foo.stubs.JsonSnippets;` is the proper import of the class and I don't need a public constructor for a class that only contains static members - am I right? – Michael Lihs Aug 04 '16 at 08:51
0

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.

Michael Lihs
  • 7,460
  • 17
  • 52
  • 85