Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build executable .jar with external .jar dependencies copied in a lib folder

I am using IntelliJ IDEA and Java. I have my main program, named SearchEngine which should build an executable SearchEngine.jar. However, there are dependencies in my code to 3 extra .jar files. I have added those dependencies and my program is working fine.

I want to build an executable .jar that does not include the 3 extra .jar files inside it, but instead, it copies them in a lib folder. For that matter I selected the following option:

1

When I don't change the settings in the Artifacts project settings tab, I get 4 .jar files, 1 of which is my executable and 3 are the extra .jar files. This way, everything works fine.

2

However, when I try and add the 3 extra .jar files inside a lib folder, my executable does not work, even though the 3 extra .jars are getting copied in a lib folder. How to make this work ?

3

like image 400
dimitris93 Avatar asked Jul 07 '15 00:07

dimitris93


1 Answers

Manually editing the MANIFEST.MF file like below (adding libs/ in front of every .jar name), fixed it.

Before:

Class-Path: lucene-core-4.10.2.jar lucene-queryparser-4.10.2.jar lucen
 e-analyzers-common-4.10.2.jar

After:

Class-Path: libs/lucene-core-4.10.2.jar libs/lucene-queryparser-4.10.2.jar
 libs/lucene-analyzers-common-4.10.2.jar
like image 134
dimitris93 Avatar answered Nov 19 '22 16:11

dimitris93