title: How to use the apache commons java library on Ubuntu?
body: <p>I am a Java beginner and trying to figure out how to use the apache commons lib.</p>
  
  <p>Here is a source file <code>Randstr.java</code>:</p>
  
  <pre><code>import org.apache.commons.lang3.RandomStringUtils;
  
  class Randstr {
      public static void main(String[] args) {
          String s = RandomStringUtils.random(12);
          System.out.println(s);
      }
  }
  </code></pre>
  
  <p>I have the <code>commons-lang3-3.1.jar</code> file in /usr/share/java/ and have created a symlink in the current dir. Then I compiled it like this: <code>javac -cp  commons-lang3-3.1.jar Randstr.java</code>, the complilation was fine, but when I execute <code>java Randstr</code>, I got the following error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/RandomStringUtils
          at Randstr.main(Randstr.java:5)
  Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.RandomStringUtils
          at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
          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:424)
          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
          ... 1 more
  </code></pre>
  
  <p>And if I don't specify the jar file in the classpath, it will not even compile:</p>
  
  <pre><code>javac -cp . Randstr.java
  
  # Randstr.java:1: error: package org.apache.commons.lang3 does not exist
  # import org.apache.commons.lang3.RandomStringUtils;
  #                                ^
  # Randstr.java:5: error: cannot find symbol
  #         String s = RandomStringUtils.random(12);
  #                    ^
  #   symbol:   variable RandomStringUtils
  #   location: class Randstr
  # 2 errors
  
  javac -cp /usr/share/java/  Randstr.java
  
  # Randstr.java:1: error: package org.apache.commons.lang3 does not exist
  # import org.apache.commons.lang3.RandomStringUtils;
  #                                ^
  # Randstr.java:5: error: cannot find symbol
  #         String s = RandomStringUtils.random(12);
  #                    ^
  #   symbol:   variable RandomStringUtils
  #   location: class Randstr
  # 2 errors
  </code></pre>
  
  <p>From reading other questions on stackoverflow, I see this can be solved by using an IDE, but I prefer a simple editor at the moment.</p>