[英]Jar file doesn't work outside the project folder
My jar file doesn't work outside the project folder, unless i put it in the same directory as the lib folder. 我的jar文件在项目文件夹之外无法工作,除非我将其与lib文件夹放在同一目录中。 When i run the jar from command line i get this:
当我从命令行运行jar时,得到以下信息:
C:\Users\Computer>java -jar SG.jar
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/hiber
nate/cfg/AnnotationConfiguration
at view.PessoaView.<init>(PessoaView.java:27)
at view.PessoaView$7.run(PessoaView.java:291)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.AnnotationConfigu
ration
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 16 more
The same with other "windows", cause my application has many menu itens. 与其他“窗口”相同,因为我的应用程序具有许多菜单项。 I have extracted the jar file, just to check and there's no lib folder there.
我已经提取了jar文件,只是为了检查,那里没有lib文件夹。 I believe it should.
我相信应该。 The jar files needed for hibernate and all others required are all in the lib folder.
休眠所需的jar文件和所有其他所需的jar文件都在lib文件夹中。 Can someone help?Thanks.. And here is a link to a similar question:
有人可以帮忙吗?谢谢。这是一个类似问题的链接:
why doesn't my jar file run outside netbeans? 为什么我的jar文件不在netbeans之外运行? ?
?
Your problem is that your jar does not includes dependancies that it requires for execution. 您的问题是您的jar不包含执行所需的依赖项。
Your program requires hibernate jars. 您的程序需要休眠jar。 You can compile all dependancies with your current jar using maven.
您可以使用maven使用当前jar编译所有依赖项。
Try this : Build jar with dependancies 试试这个: 建立依赖关系的罐子
Jar file can not contain any other jar files. jar文件不能包含任何其他jar文件。 Some tools like ant, can pack several jars inside one you can take a look on the ant.
某些工具(例如蚂蚁)可以将多个罐子装在一个罐子中,您可以看一下蚂蚁。 Another way is directly specify class path to your libraries during running using
java -cp
instead of java -jar
另一种方法是在运行期间使用
java -cp
而不是java -jar
直接指定库的类路径
您可以在运行期间使用java -cp /直接指定所需库的类路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.