Solved

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

Posted on 2009-05-06
10
771 Views
Last Modified: 2013-11-10
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
Comment
Question by:bluegreenone
  • 6
  • 3
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24321370
how are you running it?
and whats your manifest look like?

0
 

Author Comment

by:bluegreenone
ID: 24321955
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
 
LVL 92

Expert Comment

by:objects
ID: 24321980
try it with all the jars on one line

0
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 

Author Comment

by:bluegreenone
ID: 24325270
Thanks for the suggestion. Tried it.  Still getting the same error.
0
 
LVL 92

Expert Comment

by:objects
ID: 24332426
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
 

Author Comment

by:bluegreenone
ID: 24335515
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
 

Expert Comment

by:tgexpert
ID: 24345024
Does your classpath has Classes directory in it?
0
 

Author Comment

by:bluegreenone
ID: 24345338
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
 

Author Comment

by:bluegreenone
ID: 24345364
Nope. Added my own class path to the manifest Class-Path, and still get the same result.
0
 

Accepted Solution

by:
bluegreenone earned 0 total points
ID: 24390554
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question