0

I´m trying run a java jar with classpath argument like

I need run in this format:

java -cp "hibernateexample-0.0.1-SNAPSHOT.jar" 
com.javacodegeeks.snippets.enterprise.hibernate.App

But i receive this error...

Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/service/ServiceRegistry
    at com.javacodegeeks.snippets.enterprise.hibernate.service.BookService.<init>(BookService.java:13)
    at com.javacodegeeks.snippets.enterprise.hibernate.App.main(App.java:11)

How do I run the java jar with hibernate dependencies without mistakes?

In eclipse it works fine.

eli-k
  • 10,898
  • 11
  • 40
  • 44
Mister B
  • 123
  • 2
  • 15

2 Answers2

0

You have to link the depended jars to your Java runtime.

java -cp "hibernateexample-0.0.1-SNAPSHOT.jar;lib/*" com.javacodegeeks.snippets.enterprise.hibernate.App

You can also run your program in an IDE.

albi9
  • 13
  • 4
  • You may also consider packaging all dependencies into a single JAR: https://stackoverflow.com/questions/19150811/what-is-a-fat-jar – david a. Nov 24 '17 at 11:16
  • no, as david said, either add the dependencies to the jar or you provide the `java` executable with the path to the dependent libraries. – albi9 Nov 24 '17 at 13:34
0

If you run your java program from any IDE like Eclipse or any another do not need to explicitly set environment variable CLASSPATH or PATH but if you try to run from terminal (in unix/linux/mac) or from command prompt ( in windows) you have to set your CLASSPATH or PATH as per requirement either temporarily or permanently. for more details you can visit: https://www.mysoftkey.com/java/path-and-classpath-in-java/