简体   繁体   English

Jar文件找不到库

[英]Jar file not finding libraries

So I have a small Java program with some gui that I have runnning in eclipse just fine. 所以我有一个小的Java程序和一些我在eclipse中运行的gui就好了。 I followed the fatjar tutorial to create the .jar, but when I try to run the .jar the first gui window appears but none of the functions work. 我按照fatjar教程创建了.jar,但是当我尝试运行.jar时,会出现第一个gui窗口,但没有一个函数可以工作。 When I ran it in cp, clicking the button generated an exception basically saying some of the object types could not be resolved as type, all of which were from import libraries. 当我在cp中运行它时,单击该按钮会生成一个异常,基本上说某些对象类型无法解析为类型,所有这些都来自导入库。 Has anyone seen this before, I tried using this program jarfix for an issue similar to mine, but nothing. 有没有人见过这个,我尝试使用这个程序jarfix的问题类似于我的,但没有。

Please define 请定义

When I ran it in cp 当我在cp中运行它

The format of the java command should look something like java命令的格式应该类似于

java -cp /path/to/jars com.main.class

You could start locating the source of the problem by opening the jar file with an archive program (eg winzip) and look if the class / type is included in the jar file or not. 您可以通过使用存档程序(例如winzip)打开jar文件来查找问题的根源,并查看类/类型是否包含在jar文件中。

If it is there it might be a classpath issue. 如果它在那里它可能是类路径问题。 If it is not there something is wrong with building the jar file. 如果不存在构建jar文件的问题。 Musn't the included jar file be set in the "Order and Export" tab in the java buildpath dialog? 在java buildpath对话框的“Order and Export”选项卡中是否设置了包含的jar文件?

An alternative would to place all those jar files in the same folder. 另一种方法是将所有这些jar文件放在同一个文件夹中。 ie if your application jar file is App.jar and other dependencies are A.jar and B.jar . 即,如果您的应用程序jar文件是App.jar ,其他依赖项是A.jarB.jar Then drop A.jar and B.jar in the same folder as App.jar . 然后放下A.jarB.jar在同一文件夹中App.jar

If you double click on App.jar it will by taking the other dependencies in the same folder by default. 如果双击App.jar ,它将默认采用同一文件夹中的其他依赖项。

I am not aware of fatjar. 我不知道胖子。 But I faced similar problem, might be somewhere it is linked to your issue. 但是我遇到了类似的问题,可能是某个地方与你的问题有关。

In my case everything was working when I was running through eclipse, but when I created JAR using Eclipse I faced issue as what you are facing, but in my case it was issue of accessing resources inside JAR File. 在我的情况下,当我在eclipse中运行时,一切都正常工作,但是当我使用Eclipse创建JAR时,我面临的问题就是你面临的问题,但在我的情况下,这是访问JAR File中的资源的问题。

So solution was, Right Click -> Export as -> Jar, here check the box "Add Directory Entries" and then create the JAR. 所以解决方案是,右键单击 - >导出为 - > Jar,此处选中“添加目录条目”框,然后创建JAR。 Ans all worked. Ans一切顺利。

Above all, first you should check whether the jar which is generate is correct or not by just open it with winrar or similar tool and see all classes and resources are placed properly. 最重要的是,首先你要检查生成的jar是否正确,只需用winrar或类似的工具打开它,看看所有类和资源是否正确放置。

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

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