title: Java: Compiling and running multiple packages from the command-line
body: <p>I created multiple packages and want to compile and run them. I fiddled around with <code>javac</code> and <code>java</code> and learned about how packages should be named and how a project should be structured. I hope I got all right. But I fail at compilation and running the stuff. I know I could use an IDE for this, but I want to try it with the command-line tools just for curiousity.
  Here is how my project is organized:</p>
  
  <pre><code>Project
    + src
      + net
        + chris
          + dojo
              - Program.java
            + datastructures
              - Queue.java
              - LinkedList.java
            + sorting
              - MergeSort.java
    + bin
      + net
        + chris
          + dojo
              - Program.class (should be here but missing because compilation fails)
            + datastructures
              - Queue.class
              - LinkedList.class
            + sorting
              - MergeSort.class
  </code></pre>
  
  <p>Compilation for the classes in the "datastructures" and "sorting" packages is working fine. Here are the commands I used. The folder structure in the "bin" folder is automatically created by the compiler.</p>
  
  <pre><code>javac -d bin src\net\chris\dojo\datastructures\*.java
  javac -d bin src\net\chris\dojo\sorting\*.java
  </code></pre>
  
  <p>The problem is when I try to compile "Program.java" (thats the test class I run from the command-line) the compiler is throwing errors, because it cannot find the packages "net.chris.dojo.datastructures" and "net.chris.dojo.sorting".
  Here is the compilation command:</p>
  
  <pre><code>javac -d bin src\net\chris\dojo\Program.java
  </code></pre>
  
  <p>This is the output I get: </p>
  
  <pre><code>src\net\chris\dojo\Program.java:3: error: cannot find symbol
  import net.chris.dojo.datastructures;
                       ^
  symbol:   class datastructures
  location: package net.chris.dojo
  src\net\chris\dojo\Program.java:4: error: cannot find symbol
  import net.chris.dojo.sorting;
                       ^
  symbol:   class sorting
  location: package net.chris.dojo
  src\net\chris\dojo\Program.java:11: error: cannot find symbol
              MergeSort.sort(values);
              ^
  symbol:   variable MergeSort
  location: class Program
  src\net\chris\dojo\Program.java:12: error: cannot find symbol
              Queue queue = new Queue();
              ^
  symbol:   class Queue
  location: class Program
  src\net\chris\dojo\Program.java:12: error: cannot find symbol
              Queue queue = new Queue();
                                ^
  symbol:   class Queue
  location: class Program
  src\net\chris\dojo\Program.java:13: error: cannot find symbol
              LinkedList list = new LinkedList();
              ^
  symbol:   class LinkedList
  location: class Program
  src\net\chris\dojo\Program.java:13: error: cannot find symbol
              LinkedList list = new LinkedList();
                                    ^
  symbol:   class LinkedList
  location: class Program
  7 errors
  </code></pre>
  
  <p>Thats the code of my class files:</p>
  
  <p>Queue.java</p>
  
  <pre><code>package net.chris.dojo.datastructures;
  
  public class Queue {
      ...
  }
  </code></pre>
  
  <p>LinkedList.java</p>
  
  <pre><code>package net.chris.dojo.datastructures;
  
  public class LinkedList {
      ...
  }
  </code></pre>
  
  <p>MergeSort.java</p>
  
  <pre><code>package net.chris.dojo.sorting;
  
  public class MergeSort {
      ...
  }
  </code></pre>
  
  <p>Program.java</p>
  
  <pre><code>package net.chris.dojo;
  
  import net.chris.dojo.datastructures;
  import net.chris.dojo.sorting;
  
  public class Program {
  
      public static void main(String[] args) {
          int[] values = { 9, 4, 6, 2, 0, 3, 8, 1, 7, 5 };
          MergeSort.sort(values);
          Queue queue = new Queue();
          LinkedList list = new LinkedList();
      }
  
  }
  </code></pre>
  
  <p>I would run it with this command:</p>
  
  <pre><code>java -cp bin net.chris.dojo.Program
  </code></pre>
  
  <p>I execute all commands in the root folder of the project.
  Thanks for your help.</p>