Solved

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

Posted on 2009-05-06
10
765 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now