Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Packaging and running modular project NoClassDefFoundError

 
Bartender
Posts: 369
44
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all. I have been having trouble running my modular application after packaging it.

It is a simple modular application. I have three modules: hotel.main (contains the entry-point hotel.main/hotel/main/Main.java), hotel.types and database.

To give you an idea of what is happening:
hotel.types just exports its only package.

I can easily compile it at the command line withfrom the '.' directory on the tree above. I can then run it with
I’m running into trouble when I package my modules, however. After navigating to ./jars I call jar like this: Now I have my three jars in the jars directory: hotel.main.jar, hotel.types.jar and database.jar.

I tried to run the application from the jars dir withI get Exception in thread "main" java.lang.NoClassDefFoundError: persistence/database/Database
at hotel.main.Main.main(Main.java:11)
Caused by: java.lang.ClassNotFoundException: persistence.database.Database
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
The class loader can’t find database/persistence/database/Database.class. Why is this happening? Running doesn’t produce any output.
 
Sheriff
Posts: 22512
122
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
So your module JAR files are in the jar folder, right? So why don't you add that to your module path instead of the current directory (.)? Because the current directory can only work if that's the directory where your module JAR files are located.
 
Jj Roberts
Bartender
Posts: 369
44
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need some sleep. Of course you are supposed to load the jars onto the module path and run as normal. .    I realised my mistake, and was typing this as you replied. That is what I have always done! Thanks for your reply
 
Rob Spoor
Sheriff
Posts: 22512
122
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic