1

Here's what I've got:

/myjava/compile.cmd
/myjava/src/a/HelloWorld.java
/myjava/src/b/Inner.java
/myjava/src/b/Inner2.java
/myjava/bin

HelloWorld:

package a_pack;

import b_pack.Inner;
import b_back.Inner2; 

public class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Hello, World");     

        Inner myInner = new Inner(); 
        myInner.myInner(); 

        Inner2 myInner2 = new Inner2();
        myInner2.myInner(); 

    }

}

Inner.java

package b_pack; 

public class Inner {

    public void myInner() {
        System.out.println("Inner Method");
    }

}

Inner2.java

package b_pack; 

public class Inner2 {

    public void myInner() {
        System.out.println("SecondInner");
    }

}

Now what I'm trying to do is compile this so I can run.

I could compile it with:

javac -d bin src/a/HelloWorld.java src/b/Inner.java src/b/Inner2.java

But I want to use a generic command that doesn't require listing every subfolder. How do I do this?

dwjohnston
  • 11,163
  • 32
  • 99
  • 194

1 Answers1

3

Since your HelloWorld class imports references to the Inner and Inner2 classes, you can use javac sourcepath flag to compile all the three classes :

javac -d bin -sourcepath src src/a/HelloWorld.java
Patrick B.
  • 1,257
  • 10
  • 18
  • yeah, nah, that gives me `package b_pack does not exist`. http://pastebin.com/pxQJJJyw – dwjohnston May 15 '13 at 23:38
  • That's weird...From which directory are you calling the javac command? – Patrick B. May 15 '13 at 23:42
  • Yeah, you didn't create a `b_pack` package. you created `a.pack` and `b.pack` packages. So you have to modify the names of the packages in the source files. In `HelloWord` class, you must have package ` a.pack` instead of `package a_pack`. In the two other classes, you must have `package b.pack` instead of `package b_pack`. Hope it helps. – Patrick B. May 15 '13 at 23:54
  • Ok, yup changing the src/a and src/b folders to src/a_pack and src/b_pack fixed it. Thanks. – dwjohnston May 16 '13 at 00:13