I'll kick myself later - Java NoClassDefFoundError

Status
Not open for further replies.

Trilby

Ars Tribunus Militum
1,690
So it's been awhile since I've done any java coding (we're a C# shop at work) and I'm a little rusty. I'm also missing the hand holding that .NET does for you in terms of 'just making stuff work'.

So I'm making a GWT app in Eclipse (gonna deploy on App Engine) and I'm trying to use the Restlet framework to avoid using RPC (I want to be able to have iOS etc clients access the same server service). I'm getting a NoClassDefFoundError at run-time for the ClientProxy class (part of the restlet core API jar). Now I've got the jar in the WEB-INF/lib folder and I configured my build path so it's there (is there a difference between adding a file as a JAR and an External JAR?). Everything compiles nicely so I know it's there but then poof, it explodes at run time.

What am I overlooking here, I'm sure it's obvious.
 

agifford

Ars Tribunus Militum
2,142
Trilby":3c92a7l4 said:
(is there a difference between adding a file as a JAR and an External JAR?).

I believe adding as a jar means the jar is within the project structure, and it is referenced using a project relative path.
An external jar can be external to the project and is referenced with an absolute path.

External (the absolute paths really) doesn't work so well with multiple people and a source controlled project. Bob doesn't have c:\trilby\jars for example.

You can also use jars exported from another project, which is what i would do if they arent located within your project.

Trilby":3c92a7l4 said:
Everything compiles nicely so I know it's there but then poof, it explodes at run time.

How are you running things? The eclipse classpath is only known to eclipse. If you are running using eclipse's run menu, it ought to work.

If you are running from something external, you need to be sure your CLASSPATH env var/java -cp cmd line option is setup properly. You could look into an ant buildscript for unifying your run & build classpaths. Or you could script something up that parses the eclipse .classpath config file.
 
My guess is that you have two different versions of the same library. You have the Eclipse version with the JAR file that you're using to compile, and then you've got another older version in WEB-INF/lib that is missing the class you need. You'll compile fine, but if you open up the jar file in the WEB-INF/lib directory, you'll see the class is literally missing.
 
Status
Not open for further replies.