views:

317

answers:

1

Hi!

I'm not being able to import a particular class (FinanceService) from a jar. All the others work fine, including the inner-class FinanceService$Versions. I'm getting a NoClassDefFound exception, and I'm not sure how to proceed.

This exception occurs, paraphrasing an answer I've found here, when the source was successfully compiled, but at runtime, the required class files were not found, but I can clearly see it inside the .jar, whose first elements are:

META-INF/
META-INF/MANIFEST.MF
com/
com/google/
com/google/gdata/
com/google/gdata/client/
com/google/gdata/client/finance/
com/google/gdata/data/
com/google/gdata/data/finance/
com/google/gdata/client/finance/FinanceService$Versions.class
com/google/gdata/client/finance/FinanceService.class
com/google/gdata/client/finance/FinanceUtilities.class
com/google/gdata/client/finance/PortfolioQuery.class

Just to be sure, I rebuilt the jars, and still got the same error. Since it is the only class that both has an inner class and is failing to load, I considered the hypothesis that there must be a special way of loading it, but this code proves the contrary. Any idea what to do?

Thanks!

+3  A: 

That jar apparently has lots of dependencies, make sure you have all of them on CLASSPATH when you start Clojure. Also make sure you aren't mixing versions. I skipped the download link for gdata-finance-2.0.jar that you have up there, and instead downloaded http://gdata-java-client.googlecode.com/files/gdata-src.java-1.26.0.java.zip from the project page you linked, which came with a ton of jar files in gdata/java/lib, one of which was the finance jar. So I unzipped everything and did this:

$ java -cp /path/to/clojure.jar:gdata/java/lib/* clojure.main
Clojure 1.2.0-master-SNAPSHOT
user=> (import '(com.google.gdata.client.finance FinanceService))
com.google.gdata.client.finance.FinanceService

This apparently worked. But now FinanceService$Versions doesn't exist. It doesn't exist in FinanceService.java either. It's probably a different version of the library than what you are using, would be my guess.

If you're getting NoClassDefFound, be sure you're paying attention to what class it isn't finding. FinanceService might be missing, but it might also be complaining that one of its dependencies is missing.

Brian Carper