简体   繁体   English

Jar文件在项目文件夹外不起作用

[英]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.

相关问题 Jar文件在Web服务器上不起作用 - Jar file doesn't work on the web server Jar 文件引用 Maven jar 文件不能始终如一地工作 - Jar file referencing Maven jar file doesn't work consistently 可运行的Jar文件不起作用,但是源代码可以正常工作。 Maven项目JavaFX - Runnable Jar file doesn't work but the source code works fine. Maven Project JavaFX IntelliJ gradle项目不会复制资源文件夹外的资源 - IntelliJ gradle project doesn't copy resources outside resources folder 为什么我的jar文件不在netbeans之外运行? - why doesn't my jar file run outside netbeans? 如何从Project的文件夹中加载图像,音频以在.jar文件中工作 - How to load images,audio from folder in Project to work in .jar file 导出到jar后的eclipse项目不起作用 - eclipse project after exporting to jar doesn't work 在jar文件文件夹外运行bat文件 - Run the bat file outside the jar file folder Eclipse导出文件jar不包含文件夹 - Eclipse export file jar doesn't contain folder ClassLoader.getResource()对jar中的图标文件不起作用。 图标必须存在于包含jar的文件夹中 - ClassLoader.getResource() doesn't work for the icon files in a jar. The icons need to be present in the folder containing jar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM