0

I am on linux and my folder structure is

java
  --main
      --Main.java
  --aux
      --pckg
          --Aux.java

Source code

Main.java

import pckg.Aux;
public class Main {
    public static void main(String[] args) {
        System.out.println("Main main");
        Aux.method();
    }
    public static void method() {
        System.out.println("Main method");
    }
}

Aux.java

package pckg;
public class Aux {
    public static void main(String[] args) {
        System.out.println("Aux main");
        Main.method();
    }    
    public static void method() {
        System.out.println("Aux method");
    }
}

I try to compile this file with command
(in main directory)

javac Main.java -classpath .:../aux 

So I understand it this way. I need to set classpath to "." which is my current directory (where Main.java is located) and to "../aux" because pckg.Aux class is there.

But I get this error:

../aux/pckg/Aux.java:6: error: cannot find symbol
Main.method();
^
  symbol:   variable Main
  location: class Aux
1 error

looks like Main class cannot be located from within Aux class. But path to main is in the classpath. So where am I wrong here?

user1745356
  • 4,462
  • 7
  • 42
  • 70

1 Answers1

3

This doesn't work. For an explanation, see: How to access java-classes in the default-package?

Community
  • 1
  • 1
Wouter
  • 3,976
  • 2
  • 31
  • 50