title: Java: Error: Could not find or load main class Hello when trying to import an external library
body: <p>I know it's a common question, but I have read all the other answers and couldn't find a solution. I am trying to understand the Java classpath, but I run into the <code>Error: Could not find or load main class Hello</code> when I try to specify an external library.</p>
  
  <p>I started with this simple program, which resides directly in my home directory:</p>
  
  <pre><code>import java.util.*;
  
  public class Hello {
      public static void main(String[] args) {
          Date date = new Date();
          System.out.println("Hello world");
      }
  }
  </code></pre>
  
  <p>This compiles and runs just fine...</p>
  
  <pre><code>[user ~]&gt; ls -l
  Hello.java
  [user ~]&gt; javac Hello.java
  [user ~]&gt; ls -l
  Hello.java
  Hello.class
  [user ~]&gt; java Hello
  Hello world
  </code></pre>
  
  <p>...which tells me that the classpath environment variable is set correctly (because it finds the java.util package).</p>
  
  <p>Yet when I try to import a random 3rd party package and specify its location in the <code>-classpath</code>I get the error:</p>
  
  <pre><code>[user ~]&gt; cat Hello.java
  import java.util.*;
  import org.apache.commons.lang3.time.*;
  
  public class Hello {
      public static void main(String[] args) {
          StopWatch sw = new StopWatch();
          Date date = new Date();
          System.out.println("Hello world");
      }
  }
  [user ~]&gt; ls .m2/repository/org/apache/commons/commons-lang3/3.3.1
  commons-lang3-3.3.1.jar
  [user ~]&gt; javac -classpath ~/.m2/repository/org/apache/commons/commons-lang3/3.3.1/commons-lang3-3.3.1.jar Hello.java
  [user ~]&gt; java -classpath ~/.m2/repository/org/apache/commons/commons-lang3/3.3.1/commons-lang3-3.3.1.jar Hello
  Error: Could not find or load main class Hello
  </code></pre>
  
  <p>Could someone give me an idea what I'm doing wrong here?</p>