title: Opening .xlsx file with Apache POI gives NoClassDefFoundError InvalidFormatException
body: <p>I'm having trouble getting the import of all the required .jar files working correctly.
  My end goal is simply to read in an excel spreadsheet (more specifically .xlsx files) to check whether the speed of Apache POI will work for future applications. </p>
  
  <p><b>My question is why am I getting thrown the error...</p>
  
  <blockquote>
    <p>java.lang.NoClassDefFoundError: org/apache/poi/openxml4j/exceptions/InvalidFormatException</p>
  </blockquote>
  
  <p>...when I can see in the class InvalidFormatException at /org/apache/poi/openxml4j/exceptions/ in the 'file poi-ooxml-3.9-20121203.jar'?</b></p>
  
  <p>I haven't done programming in Java in a while and I'm hoping for my own sanity that I've made a stupid mistake. My code seems to be compiling correctly but I have the above error message when I try run the program. I have done some research into my issue but haven't been able to find someone in my situation. They usually just forget/don't have a required .jar file. Maybe I'm in the same boat but hopefully you'll be able to tell me.</p>
  
  <p>I'll give a breakdown of my logic. Here is the code in TestExcel.java</p>
  
  <pre><code>import java.io.FileInputStream; 
  import java.io.FileNotFoundException; 
  import java.io.FileOutputStream; 
  import java.io.IOException; 
  import java.io.InputStream; 
  
  import org.apache.poi.ss.usermodel.Cell; 
  import org.apache.poi.ss.usermodel.Row; 
  import org.apache.poi.ss.usermodel.Sheet; 
  import org.apache.poi.ss.usermodel.Workbook; 
  import org.apache.poi.ss.usermodel.WorkbookFactory; 
  
  import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  
  public class TestExcel 
  {
      public static void main(String[] args) 
      { 
          InputStream inp; 
          try 
          { 
              inp = new FileInputStream("cost.xlsx"); 
  
              Workbook wb; 
              try { 
                  wb = WorkbookFactory.create(inp); 
              } 
              catch (FileNotFoundException e) { 
                  e.printStackTrace(); 
              } 
          } 
          catch (InvalidFormatException e) { 
              e.printStackTrace(); 
          } 
          catch (IOException e) { 
              e.printStackTrace(); 
          } 
      } 
  }
  </code></pre>
  
  <p>Here is the file 'c_test' used to compile and run the java code:</p>
  
  <pre><code>javac -classpath "/home/robsco/Webdev/java/poi/*" TestExcel.java
  java TestExcel
  </code></pre>
  
  <p>Here is the directory listing of the classpath above:</p>
  
  <pre><code>robsco@roblaptop:~/Webdev/java/poi$ ls -al
  total 26616
  drwxrwxr-x 2 robsco robsco     4096 Aug 18 18:13 .
  drwxrwxr-x 6 robsco robsco     4096 Aug 18 18:12 ..
  -rwxr-xr-- 1 robsco robsco    52915 Sep 18  2009 commons-logging-1.1.jar
  -rwxr-xr-- 1 robsco robsco   313898 Apr  5  2009 dom4j-1.6.1.jar
  -rwxr-xr-- 1 robsco robsco   121070 Apr  5  2009 junit-3.8.1.jar
  -rwxr-xr-- 1 robsco robsco   358180 Apr  5  2009 log4j-1.2.13.jar
  -rwxrw-r-- 1 robsco robsco 14841622 Aug 18 13:15 ooxml-schemas-1.1.jar
  -rwxr-xr-- 1 robsco robsco  1869113 Nov 26  2012 poi-3.9-20121203.jar
  -rwxr-xr-- 1 robsco robsco    30446 Nov 26  2012 poi-excelant-3.9-20121203.jar
  -rwxr-xr-- 1 robsco robsco   936648 Nov 26  2012 poi-ooxml-3.9-20121203.jar
  -rwxr-xr-- 1 robsco robsco  4802621 Nov 26  2012 poi-ooxml-schemas-3.9-20121203.jar
  -rwxr-xr-- 1 robsco robsco  1226511 Nov 26  2012 poi-scratchpad-3.9-20121203.jar
  -rwxr-xr-- 1 robsco robsco  2666695 Apr  5  2009 xmlbeans-2.3.0.jar
  </code></pre>
  
  <p>and the output of executing 'c_test':</p>
  
  <pre><code>robsco@roblaptop:~/Webdev/java$ ./c_test 
  Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/openxml4j/exceptions/InvalidFormatException
      at java.lang.Class.getDeclaredMethods0(Native Method)
      at java.lang.Class.privateGetDeclaredMethods(Class.java:2521)
      at java.lang.Class.getMethod0(Class.java:2764)
      at java.lang.Class.getMethod(Class.java:1653)
      at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
      at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
  Caused by: java.lang.ClassNotFoundException: org.apache.poi.openxml4j.exceptions.InvalidFormatException
      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)
      ... 6 more
  </code></pre>
  
  <p><b>I am using: </b><br>
  OS: Lubuntu 12.10 x86<br></p>
  
  <pre><code>java -version
  java version "1.7.0_25"
  Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
  
  robsco@roblaptop:~/Webdev/java/poi$ javac -version
  javac 1.7.0_25
  </code></pre>