简体   繁体   English

运行java程序的classpath

[英]Run java program classpath

I´m trying run a java jar with classpath argument like 我正在尝试运行带有类路径参数的Java jar

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? 如何在没有错误的情况下运行具有休眠依赖关系Java jar

In eclipse it works fine. 在日食中工作正常。

You have to link the depended jars to your Java runtime. 您必须将依赖的jar链接到Java运行时。

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

You can also run your program in an IDE. 您也可以在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. 如果您从Eclipse之类的IDE或其他任何IDE中运行Java程序,则无需显式设置环境变量CLASSPATH或PATH,但是如果尝试从终端(在unix / linux / mac中)或从命令提示符(在Windows中)运行,必须根据要求临时或永久设置CLASSPATH或PATH。 for more details you can visit: https://www.mysoftkey.com/java/path-and-classpath-in-java/ 有关更多详细信息,您可以访问: https : //www.mysoftkey.com/java/path-and-classpath-in-java/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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