简体   繁体   中英

Run java program classpath

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.

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM