1
votes

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?

1
Create jar file then....Smit
You need to compile all of the files you reference, not seeing a way around that.Hunter McMillen
You should set up a build script with ant or maven and let it do this thinking for you.Daniel Kaplan
@HunterMcMillen - Is there a command to say 'compile every java file in all subdirectories'?dwjohnston

1 Answers

3
votes

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