title: Tomcat's CLASSPATH is different than Java's, and it does not include "." How do I change it?
body: <p>I've been spending hours trying to figure out why I've been getting the <code>java.lang.NoClassDefFoundError</code>, and I've narrowed down the cause to Tomcat's classpath.</p>
  
  <p>I used the code below to see what the path variables hold:</p>
  
  <pre><code>out.println("Classpath: '" + System.getProperty( "java.class.path" ) + "'" );
  out.println("Ext dirs: '" + System.getProperty( "java.ext.dirs" ) + "'" );
  out.println("Library path: '" + System.getProperty( "java.library.path" ) + "'" );
  out.println("Path separator: '" + System.getProperty( "path.separator" ) + "'" );
  </code></pre>
  
  <p>And the output is:</p>
  
  <pre>Classpath: ':/usr/local/tomcat/bin/bootstrap.jar'
  Ext dirs: '/usr/lib/jvm/java-6-sun-1.6.0.16/jre/lib/ext:/usr/java/packages/lib/ext'
  Library path: '/usr/lib/jvm/java-6-sun-1.6.0.16/jre/lib/i386/server:/usr/lib/jvm/java-6-sun-1.6.0.16/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.16/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib'
  Path separator: ':'</pre>
  
  <p>As you can see, Classpath does NOT start with "." as it's supposed to, and I believe that's why my program can't find the classes that I import from subdirectories in my webapp.</p>
  
  <p>To see where the classpath is set, i did <code>grep -R bootstrap.jar /usr/local/tomcat/</code>, and came accross this: <code>CLASSPATH="$CLASSPATH":"$CATALINA_HOME"/bin/bootstrap.jar</code> (in file <code>/usr/local/tomcat/bin/catalina.sh</code>)</p>
  
  <p>This makes me believe that for some reason $CLASSPATH is empty here. However, <code>echo $CLASSPATH</code> successfully returns <code>.:/usr/lib/jvm/java-6-sun/bin:/usr/local/tomcat/lib/servlet-api.jar</code></p>
  
  <p>Can anybody help pin down the problem here?</p>
  
  <hr>
  
  <p>EDIT: All my servlet files are in <code>WEB-INF/classes/controllers/</code>, and the libraries i'm trying to load are class files in subdirectories. 
  For example, if <code>ClassName.class</code> is in the WEB-INF/classes/controllers/packagename/ directory, I add <code>package packagename</code> to the start of <code>ClassName.java</code>, and I import it using <code>import packagename.*</code> in <code>someServlet.java</code>. </p>
  
  <hr>
  
  <p>EDIT2: I have solved my problem. My main issue was that, as written below, not using the correct package names. Also, I was trying to compile from inside the <code>classes/controllers/</code> directory, instead of compiling from <code>classes/</code>. Thank you all for your help!</p>