It works fine when compiling project, but after exporting it to a runnable jar
and launching, it can't find external files and throws an error. What should I do?
Asked
Active
Viewed 220 times
5 Answers
2
Add external libraries to the manifest.mf
:
Class-Path: . MyApp_lib/extlib.jar MyApp_lib/extlib2.jar ...

Roman C
- 49,761
- 33
- 66
- 176
1
You could attempt building a fat jar
that includes all the jars. It contains a custom class loader to load the jars referenced externally by your project.
Try using http://fjep.sourceforge.net/ plugin to build a fat jar.
You can export a java project containing jars using the File -> Export -> Other -> One Jar Exporter
.
The jar thus exported works fine.

Ashutosh Jindal
- 18,501
- 4
- 62
- 91
0
You have to keep all required jars in the classpath to run your jar. Run your jar like :
java -cp extlib/* -jar yourjar.jar
OR java -cp lib1.jar:lib2.jar:.. -jar yourjar.jar

Nandkumar Tekale
- 16,024
- 8
- 58
- 85
-
what if there are, like, hundreds of them? coz that's my case – nicks Aug 20 '12 at 14:55
0
Make sure that while building the jar, you include all the used libraries(include everything from class path). This issue will happen when you refer a external jar.

Siva Arunachalam
- 7,582
- 15
- 79
- 132