简体   繁体   中英

Jar file not finding libraries

So I have a small Java program with some gui that I have runnning in eclipse just fine. 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. 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. Has anyone seen this before, I tried using this program jarfix for an issue similar to mine, but nothing.

Please define

When I ran it in cp

The format of the java command should look something like

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.

If it is there it might be a classpath issue. If it is not there something is wrong with building the jar file. Musn't the included jar file be set in the "Order and Export" tab in the java buildpath dialog?

An alternative would to place all those jar files in the same folder. ie if your application jar file is App.jar and other dependencies are A.jar and B.jar . Then drop A.jar and B.jar in the same folder as App.jar .

If you double click on App.jar it will by taking the other dependencies in the same folder by default.

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.

So solution was, Right Click -> Export as -> Jar, here check the box "Add Directory Entries" and then create the JAR. Ans all worked.

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.

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