title: setting JAVA_HOME & CLASSPATH in CentOS 6
body: <p>I have unpacked my jdk in /usr/java/.</p>
  
  <p>and I put CLASSPATH, PATH, JAVA_HOME into /etc/profile like below.</p>
  
  <pre><code>export JAVA_HOME=/usr/java/jdk1.7.0_21
  export PATH=$PATH:$JAVA_HOME/bin
  export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
  </code></pre>
  
  <p>And when I compile some java file in /usr/java/jdk1.0.7_21/bin, </p>
  
  <p>it works. But when I am doing same thing on other folder, it doesn't.</p>
  
  <p>It displays NoClassDefFoundError.</p>
  
  <p>So I have checked ClASSPATH, PATH, JAVA_HOME via echo.</p>
  
  <p>It shows like below.</p>
  
  <pre><code>[root@localhost a]# echo $JAVA_HOME
  /usr/java/jdk1.7.0_21
  [root@localhost a]# echo $PATH
  /usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/guest/bin:/usr/java/jdk1.7.0_21/bin:/usr/java/bin:/usr/java/jdk1.7.0_21/bin
  [root@localhost a]# echo $CLASSPATH
  /usr/java/jdk1.7.0_21/jre/lib/ext:/usr/java/jdk1.7.0_21/lib/tools.jar
  </code></pre>
  
  <p>I want to use java in console, What can I do fir this situation?</p>
  
  <p>Thanks in advance.</p>
  
  <p>PS. of couse I did <code>source /etc/profile</code>.</p>
  
  <p>=================The Errors what I'm facing with =======================</p>
  
  <p>when I command java A(My class name is A).</p>
  
  <pre><code>Error: Could not find or load main class A
  </code></pre>
  
  <p>case I command java -cp /home/guest/workspace/AAA/src/a/ A</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: A (wrong name: a/A)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
      at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
  </code></pre>
  
  <p>=====================full content of my code======================================
  java part. path is /usr/guest/workspace/AAA/src/a/A.java</p>
  
  <pre><code>package a;
  
  public class A {
      public static void main(String[] args) {
          System.out.println("a!\n");
      }
  }
  </code></pre>
  
  <p>/etc/profile part. left part is default.</p>
  
  <pre><code>export JAVA_HOME=/usr/java/jdk1.7.0_21
  export PATH=$PATH:$JAVA_HOME/bin
  export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
  </code></pre>
  
  <p>other parts might be helpful to solve.</p>
  
  <ul>
  <li><code>which java</code> prints "/usr/java/bin". there's symbolic link.</li>
  <li>My jdk location is /usr/java/jdk1.7.0_21. inside of ./bin every code works fine.</li>
  <li>I did not touch /root/.bash_profile. I just edited /etc/profile.</li>
  </ul>
  
  <p>Thanks for such interest. even though it does not figured out. your help was great healing to me :D Thanks again.</p>