• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 801
  • Last Modified:

Getting NoClassDefFoundError on class known to be in jar in the classpath

I'm learning Restlet by working with a small example application.  When I run the app, I get java.lang.NoClassDefFoundError: org/restlet/ext/json/JsonRepresentation.  I have org.restlet.ext.json in the subdirectory with my other external jars, including other org.restlet... jars. jar -tf org.restlet.ext.json.jar does in fact have the JsonRepresentation class in it. So, the class is in the jar and the jar is in the manifest Class-Path but the runtime is unable to resolve the class reference.

Any help would be much appreciated.
0
bluegreenone
Asked:
bluegreenone
  • 6
  • 3
1 Solution
 
objectsCommented:
how are you running it?
and whats your manifest look like?

0
 
bluegreenoneAuthor Commented:
java -jar WebSrvApp.jar

Manifest:

Main-Class: com.nynjpkg.WebSrvApp
Class-Path: com/nynjpkg/lib
                   com/nynjpkg/lib/org.restlet.jar
                   com/nynjpkg/lib/com.noelios.restlet.jar
                   com/nynjpkg/org.apache.commons.httpclient.jar
                   com/nynjpkg/org.json.jar
                   com/nynjpkg/org.restlet.ext.json.jar
0
 
objectsCommented:
try it with all the jars on one line

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
bluegreenoneAuthor Commented:
Thanks for the suggestion. Tried it.  Still getting the same error.
0
 
objectsCommented:
where exactly are the jars?

> com/nynjpkg/lib

remove that from the class-path
and make sure it has a couple of blank lines at the end

whats your manifest look like now?

0
 
bluegreenoneAuthor Commented:
My directory structure is:

Classes
     com
          nynjpkg
               lib

My jar is in Classes.
My classes are in nynjpkg
External jars are in lib
After removing com/nynjpkg/lib per your suggestion, my manifest looks like:

Main-Class: com.nynjpkg.WebSrvApp
Class-Path: com/nynjpkg/lib/org.restlet.jar com/nynjpkg/lib/com.noelios.restlet.jar com/nynjpkg/org.restlet.ext.json_2.0.jar com/nynjpkg/org.apache.commons.httpclient.jar com/nynjpkg/org.json.jar

After making your suggested change, I'm still getting the same error.
0
 
tgexpertCommented:
Does your classpath has Classes directory in it?
0
 
bluegreenoneAuthor Commented:
No. Since the error I'm getting involves a class in an external jar, I didn't think about having my own class directory in the path. I'll give it a try.
0
 
bluegreenoneAuthor Commented:
Nope. Added my own class path to the manifest Class-Path, and still get the same result.
0
 
bluegreenoneAuthor Commented:
After checking 100 times that the JsonRepresentation class was in the jar, and the jar was in my classpath, and ruling out things like misspellings, I resorted to compiling the JsonRepresentation class as part of my application package. This works and solved my problem, but I still would like to have determined why it wasn't working the other way.
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now