javacompiler-errorsjavac

javac fails with symbol not found


Here is my folder structure:

- myGame/
  - bin/
  - src/
     - common/
     - logic/
     - main/
     - messageprotocol/
     - test/
     - util/
         - Test.java
         - Rectangle.java
         - Geometry.java

I would like to compile Test.java which is in util package. However, I get symbol not found errors, I guess javac command is wrong. Also, you should know that Test.java has references to other classes within the same project (myGame).

Here is what I do:

cd myGame/
javac -d bin -classpath bin src/util/Test.java

Once I'm done with above, I'd do this and it would work (I hope):

cd myGame/bin
java Test

I have read a lot of resources and tried to apply but it didn't work for my folder structure. What am I doing wrong?

Edit: Errors I receive are:

myGame/src/util/Test.java:16: cannot find symbol
symbol  : class Rectangle
location: class util.Test
  private static final Rectangle[] rectangles = new Rectangle[someNumber];
                       ^
myGame/src/util/Test.java:16: cannot find symbol
symbol  : class Rectangle
location: class util.Test
  private static final Rectangle[] rectangles = new Rectangle[someNumber];
                                                          ^
myGame/src/util/Test.java:20: cannot find symbol
symbol  : variable Geometry
location: class util.Test
    System.out.println("Printing " + Geometry.NUMBER);
                                                      ^
myGame/src/util/Test.java:24: cannot find symbol
symbol  : variable Geometry
location: class util.Test
      serverSocket = new Circle(Geometry.NUMBER);
                                      ^
myGame/src/util/Test.java:36: cannot find symbol
symbol  : class Rectangle
location: class util.Test
            rectangles[i] = new Rectangle(number, rectangles);
                                   ^
5 errors

Solution

  • Package structure for your Test.java is util.Test so you should do:

    cd myGame/src
    javac -d ../bin -classpath ../bin util/Test.java
    

    and then try running it. hope this helps.