Just a concept that has eluded me... Anyone who can help make this understandable would be a God send.

in the directory c:/dev/myapp I have the subdir
src/com/mycompany/myapp/MyApp.java which consists of

package com.mycompany.myapp
 import com.mycompany.MyUtil
 public class MyApp {
   public static void main(String args[]) {
     new MyApp();

src/com/mycompany/util/MyUtil.java which consists of

package com.mycompany.myutil
 public class MyUtil {
  public static void Say() {

If I go into the subdir src/com/mycompany/myapp and do a compile:
javac MyApp.java
It doesn't find MyUtil.

If i move the com/mycompany/util subdir into src/com/mycompany/
it does find it. It seems like a classpath issue, but I cannot seem to get my head around it.

My ant build seems to understand what is happening and runs things fine. Any enlightenment would be appreciated.

7 Years
Discussion Span
Last Post by JamesCherrill

Spent a productive block of time with just the above code example and finagled it 2o different ways to Sunday, and I think I get it now. It's both classpath and package kind of deal. I think using Jars kind of obfuscated the knowledge for me and so when I tried doing things outside of the jar I was getting strange results.


Package names are interpreted starting from all the places in the classpath. Eg classpath begins with . (current dir), package is com.xxx.yyy - java looks for a dir com/xxx/yyy in the current dir. If it doesn't find that it does the same thing starting at the next location in the classpath etc.
Jars are treated exactly like directories.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.