• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 22684
128
Eclipse IDE Spring VI Editor 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: 22684
128
Eclipse IDE Spring VI Editor 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.
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic