0

I'm trying to write very simple app using Intellij Idea. I've put snakeyaml in folder lib created by me and imported it into my class. When I run i got error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/yaml/snakeyaml/Yaml
at ConfigStore.readConfig(ConfigStore.java:22)
at ConfigStore.<init>(ConfigStore.java:12)
at Main.main(Main.java:9)
Caused by: java.lang.ClassNotFoundException: org.yaml.snakeyaml.Yaml

I'm not using maven or anything like that. I used other libs (for example SQLite) in this project and had no problems. What am I doing wrong?

[Update] I managed to make it work but to achieve that I had to build everything from scratch this time using maven. That's not what was my original idea so this is more workaround than solution.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Smok
  • 101
  • 2
  • 11
  • Make sure the library is added to the classpath. Just adding in lib will not add to classpath. https://stackoverflow.com/questions/854264/how-to-add-directory-to-classpath-in-an-application-run-profile-in-intellij-idea – Dhaval Gajjar Mar 11 '23 at 18:20
  • Check the guide here https://www.jetbrains.com/help/idea/library.html#define-a-project-library and make sure that you have also included this library in the IDEA. – LJ replica Mar 13 '23 at 03:40

1 Answers1

1

NoClassDefFoundError comes when the class was available at compile time but somehow not available at runtime. If the static initializer block of a class throws an Exception during loading, the class will not be available for others to use.

Read more: https://www.java67.com/2012/08/what-is-noclassdeffounderror-in-java.html#ixzz7vg5HdQoZ

Hope it will help!