Java error: package 'x' does not exist

Jerfov2 picture Jerfov2 · Nov 16, 2014 · Viewed 11.7k times · Source

So I have a file tree in Linux that looks like this:

  • ~/keyboard_warriors/
    • test/
      • ConfigTest.java
    • ConfigParser.class
    • ConfigParser.java

The problem is that when I try to type in Terminal:
javac ConfigTest.java

I get the error:

ConfigTest.java:2: error: package keyboard_warriors does not exist  
import keyboard_warriors.*;  
^

This is really bugging me and I could not find any answers anywhere. If you could solve my problem, I would be a very happy person.

Answer

Makoto picture Makoto · Nov 16, 2014

It's not going to recognize a directory outside of the classpath as being part of the classpath.

What you probably want is to include another folder inside of where your test is being run:

test/
    keyboard_warriors/
        ConfigTest.java
        ConfigParser.java

This also presumes that you have declared these classes to be in the keyboard_warriors classpath, by this:

package keyboard_warriors;

Depending on how you're compiling these classes, you'd have to add it to the classpath with the -cp flag on javac.