Solved

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

Posted on 2009-05-06
10
773 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 

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

Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

Question has a verified solution.

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

Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

724 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