问题
I have a java project that I'm working on which was working until a few days ago. I'm not sure what I did to my Eclipse set-up to hose it but now I'm getting a java.lang.ClassNotFoundException when I try to run some code that accesses the google finance api. I've built a small test application that uses the google finance api on its own and that seems to work. So, I think this is a project specific problem. Any help would be greatly appreciated. Here's the stack trace:
ptolemy.kernel.util.IllegalActionException: in .RandomSearch.manager
Because:
com/google/common/collect/Maps
at ptolemy.actor.Manager.execute(Manager.java:472)
at ptolemy.actor.Manager.run(Manager.java:1119)
at ptolemy.actor.Manager$3.run(Manager.java:1160)
Caused by: java.lang.NoClassDefFoundError: com/google/common/collect/Maps
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:118)
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:100)
at com.google.gdata.client.Service.<clinit>(Service.java:546)
at AtomicBroadcast.GoogleFinance.GooglePortfolioReader.fire(GooglePortfolioReader.java:108)
at ptolemy.domains.de.kernel.DEDirector.fire(DEDirector.java:568)
at ptolemy.actor.CompositeActor.fire(CompositeActor.java:458)
at ptolemy.actor.Manager.iterate(Manager.java:714)
at ptolemy.actor.Manager.execute(Manager.java:349)
... 2 more
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Maps
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:319)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
... 10 more
Caused by: java.lang.NoClassDefFoundError: com/google/common/collect/Maps
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:118)
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:100)
at com.google.gdata.client.Service.<clinit>(Service.java:546)
at AtomicBroadcast.GoogleFinance.GooglePortfolioReader.fire(GooglePortfolioReader.java:108)
at ptolemy.domains.de.kernel.DEDirector.fire(DEDirector.java:568)
at ptolemy.actor.CompositeActor.fire(CompositeActor.java:458)
at ptolemy.actor.Manager.iterate(Manager.java:714)
at ptolemy.actor.Manager.execute(Manager.java:349)
at ptolemy.actor.Manager.run(Manager.java:1119)
at ptolemy.actor.Manager$3.run(Manager.java:1160)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Maps
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:319)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
... 10 more
回答1:
It seems that your project classpath is lacking google-collect-1.0-rc1.jar
You obviously have it on your hard drive, just edit the project classpath and add it there (or make sure it gets added by Maven/such if you use them).
回答2:
You will have to be aware of the difference between two similar error messages. I suggest you read the fantastic article "Difference between ClassNotFoundException and NoClassDefFoundError" from Sanjiv Jivan. http://www.jroller.com/sjivan/entry/difference_between_classnotfoundexception_and_noclassdeffounderror
回答3:
I run across the similiar problem. I didn't found google-collect-1.0-rc1.jar
in gdata api.
But this thread solved my problem:
- Add guava.xxx.jar into your project. Guava is a fully compatible superset of the old Google Collections Library.
- You can find guava-xxxx.jar in gdata-samples/java/deps/guava.xxxx.jar. Or download it from here.
Google Recommends Guava instead of google-collect-1.0.jar. see here
来源:https://stackoverflow.com/questions/3011726/java-lang-classnotfoundexception