title: How do I run a java program from a different directory?
body: <p>I have a java program that I would like to be able to run from anywhere on my machine.  I would like to run it from my Cygwin command prompt.  I've made scripts to call the java program.  I added the location of the java program to the classpath, and the scripts work when I run them from the java program's directory.  However, when I try to run from any other directory, I get:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: commandprogram/CommandProgram
  </code></pre>
  
  <p>This is my script:</p>
  
  <pre><code>#!/bin/sh
  CWD=`dirname "$0"`
  java -cp "$CWD/classes;$CWD/lib/AJarFile.jar" commandprogram/CommandProgram
  </code></pre>
  
  <p>Changing the java line to the following:</p>
  
  <pre><code>java -cp "$CWD/classes;$CWD/classes/commandprogram;$CWD/lib/AJarFile.jar" CommandProgram
  </code></pre>
  
  <p>produces the same results.</p>