title: How to execute a java program with external jar
body: <p>I want to run my program with guava.  If I compile my program with</p>
  
  <p>EDIT: java -> javac for the compile call</p>
  
  <pre><code>javac -cp myPackages/guava-13.0.jar MyScanner.java    
  </code></pre>
  
  <p>there is no problem.</p>
  
  <p>If I try to run</p>
  
  <pre><code>java MyScanner -cp myPackages/guava-13.0.jar 
  </code></pre>
  
  <p>I get this output on the console:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Optional
  at MyScanner.main(MyScanner.java:37)
  Caused by: java.lang.ClassNotFoundException: com.google.common.base.Optional
  at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
  ... 1 more
  </code></pre>
  
  <p>Can you tell me how I can execute the program with the external jar? </p>