title: How do I access JAR classes from within my Clojure program?
body: <p>I've been stuck for several days on something that I <em>know</em> I've gotten to work once before. I'm probably missing something obvious. Any help would be appreciated.</p>
  
  <p>In my Clojure program, I want to access methods from classes originally written in Java. Let's use a specific example: org.infoml.jaxb.ObjectFactory. These classes are in a .jar file (<code>infoml-classes-1.0.jar</code>) that is a double-clickable Java application. If you open up the jar file, you see the folder for the top-level segment of the Java classes' package:</p>
  
  <pre><code>macscooter:infoml-classes-1.0 folder gw$ find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
  .
  |____META-INF
  | |____MANIFEST.MF
  |____org
  | |____infoml
  | | |____infocardOrganizer  &lt;&lt;&lt;&lt;&lt;&lt; Java application's classes
  | | | |____AFileFilter.class
  
        |  ... many classes omitted here
  
  | | | |____UniqueContentListener.class
  | | | |____UniqueContentModel.class
  | | |____jaxb
  | | | |____AgentContainerLocationType.class
  | | | |____AgentType.class
  
        |  ... many classes omitted here
  
  | | | |____ObjectFactory.class   &lt;&lt;&lt;&lt;&lt;&lt; HERE IT IS
  
        |  ... many classes omitted here
  
  | | | |____TableRowType.class
  | | | |____TableType.class
  macscooter:infoml-classes-1.0 folder gw$
  </code></pre>
  
  <p>In my Clojure program, I import it (from file <code>cardmaker.clj</code>):</p>
  
  <pre><code>(ns infwb.cardmaker
    (:gen-class)
    (:import
     (javax.xml.bind  JAXBContext  JAXBException  Marshaller
              Unmarshaller)
      (org.infoml.jaxb        ContentAgentContainerLocationType
              InfomlFile  InfomlType  ObjectFactory  PType  &lt;&lt;&lt;&lt;&lt;&lt; HERE IT IS
              RichTextWithExactType
              SelectorsType
              SimpleRichTextType)
     (java.io  ByteArrayOutputStream IOException)))
  </code></pre>
  
  <p>When I print out the classpath that the REPL sees, it's there (as <code>infoml-classes-1.0.jar</code>):</p>
  
  <pre><code>infwb.cardmaker&gt; (doseq [p (.getURLs (java.lang.ClassLoader/getSystemClassLoader))] (println (.getPath p)))
  /Users/gw/tech/clojurestuff/cljprojects/infwb/src/
  /Users/gw/tech/clojurestuff/cljprojects/infwb/test/
  /Users/gw/tech/clojurestuff/cljprojects/infwb/classes/
  /Users/gw/tech/clojurestuff/cljprojects/infwb/lib/clojure-1.3.0-SNAPSHOT.jar
  /Users/gw/tech/clojurestuff/cljprojects/infwb/lib/clojure-contrib-1.2.0.jar
  /Users/gw/tech/clojurestuff/cljprojects/infwb/lib/infoml-classes-1.0.jar  &lt;&lt;&lt;&lt;&lt;&lt; HERE IT IS
  /Users/gw/tech/clojurestuff/cljprojects/infwb/lib/piccolo2dcore-1.3.jar
  /Users/gw/tech/clojurestuff/cljprojects/infwb/lib/piccolo2dextras-1.3.jar
  /Users/gw/tech/clojurestuff/cljprojects/infwb/lib/sxqj-beta2.jar
  /Users/gw/tech/clojurestuff/cljprojects/infwb/lib/dev/clojure-1.2.0.jar
  /Users/gw/tech/clojurestuff/cljprojects/infwb/lib/dev/swank-clojure-1.3.0-20110104.084027-21.jar
  nil
  infwb.cardmaker&gt;
  </code></pre>
  
  <p>However, when I try to compile the file cardmaker.clj (by either C-c C-k or <code>(load-file "src/infwb/cardmaker.clj")</code>, I get the following exception:</p>
  
  <pre><code>Could not initialize class org.infoml.jaxb.ObjectFactory
    [Thrown class java.lang.NoClassDefFoundError]
  </code></pre>
  
  <p>I've gone as far as rebooting my machine to try to eliminate inadvertent crud as a source of the problem. I've researched several things on the Internet--no luck. I've looked at the MANIFEST.MF file for clues, and stripped the jar file down to just the classes I need. I've slept on it overnight twice now--still no solution.</p>
  
  <p>Using existing Java classes from within Clojure is a useful thing to do. I'd appreciate the help that anyone might be able to give me. Thanks.</p>
  
  <hr>
  
  <p>ADDENDUM: My problem was caused by a number of factors, including a missing jar file. @kotarak's answer was spot on. Thanks.</p>