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?

2
  • not related to your problem, just want to know which OS you are using Commented Nov 2, 2013 at 15:58
  • Okay, I tried but not able to create a class with name AUX USing windows 8 Commented Nov 2, 2013 at 16:01

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.