• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

NoClassDefFoundError for an imported json library

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

I have run into into some weird runtime error. I have a json data file that I am trying to parse into my code . I am using json-simple-1.1.1.jar external library that I have added to my classpath and verified that it exists there by doing echo $CLASSPATH.

When I compile my code using javac codeTest.java the program compiles with no issues .

But when I try to run the program using java -classpath . codeTest I am receiveing the error : java.lang.NoClassDefFoundError: org/jason/simple/parser/ParseException.

I have opened the json-simple-1.1.1.jar folder and verified that ParseException.class does exist in the folder.

If I run the code without the class path (i.e. java codeTest) then I am receiving "could not find or load main class codeTest", which is expected.

Please help me troubleshoot this.

Thank you

my code snippet :


 
Sheriff
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Harsh Bhasin wrote:java -classpath . codeTest


There's your problem - the library may exist, but the JVM is not using it. By specifying the classpath as ., you're saying it's the current directory, and nothing else. Current directory means class files in the current directory (including package structure), but JAR files in the same directory are not included. You need to add that as well: java -classpath .;json-simple-1.1.1.jar codeTest (assuming you're on Windows, otherwise replace the ; with a :).
 
Harsh Bhasin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much Rob. I knew it had to be something simple but just could not figure out what it was.

I really appreciate it.
 
Rob Spoor
Sheriff
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
You get good luck from rubbing the belly of a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic