tags:

views:

231

answers:

1

I have 3 files: /a/A.java /a/aa/AA.java /b/B.java and B.java depends on A.java and AA.java.

I basically want javac -classpath /a /b/B.java to work (i.e. have javac search below /a). Is there any way I can do this?

+3  A: 

The short answer is no, that's not how classpath directories work.

Each classpath directory is regarded as the root of a package structure. Each package is a directory within the root. So, javac will do so automatically if aa is a package directory and a is the root. You're classes would look like this:

/a/A.java

class A {}

/a/aa/AA.java

package aa;
class AA {}

/b/B.java

package b;
import aa.AA;

class B {
  private AA aaInstance;
  private A aInstance;
}

Because A has no package, it's placed in the root package.

Otherwise, you have to set each source dir explicitly.

sblundy