Question

What would cause a jar to be added successfully to an Eclipse Java project but then at runtime some of the classes from that jar are not found with ClassNotFound exceptions?

Was it helpful?

Solution

The CLASSPATH variable at runtime is likely set incorrectly or you missed adding some classes to your jar file.

OTHER TIPS

@ojblass almost certainly has it right. Just to extend it, you can dump the jar file with the jar(1) tool and see if the class is there. I've had surprises from Eclipse where the project definition didn't understand what was to go into a jar file I was generating to run with java -jar.

Everybody seems to be on the right track. Why don't you, while you have the jar unzipped, add the entire thing as a source folder in your eclipse project to see if you can even load it that way? Sometimes, depending on the classloader, you can get the CNFE if your class is available multiple times on the classpath... the classloader just bails because it doesn't know which one to use.

I had this error occur up for having a missing permission. Turns out checking to see if you are connected to the internet (i.e., reachability) and permission to use the internet are separate permissions (live and learn.)

The missing permission caused the app to fail with ClassNotFound error when it tried to run a reachability test.

Hope that helps someone because this was not a fun time sink to work through.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top