Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I include external JARs in my own Project JAR

I have a Java application and created a JAR file and deployed it.

The App uses external JARs such as the Log4J JAR. When creating my JAR file, how do I include all external dependent JARs into my archive?

In order to get my App working, I'm having to copy the Log4J JAR into the same directory as my own JAR which kinda defeats the purpose of the jar. Wouldn't it be more elegant to have 1 single JAR file to deploy?

like image 832
Wilko Avatar asked Sep 16 '10 16:09

Wilko


2 Answers

If you use Eclipse, You can extract all included files into one runnable jar like this:

  1. Right click on your project name from Package Explorer and select Export.
  2. In Export screen, select Java -> Runnable JAR file and Next.
  3. Fill in the Runnable JAR File Spec screen and Finish.

You can choose whether to package dependency jars as individual jar files or extract them into the generated JAR.

like image 179
coder623 Avatar answered Sep 23 '22 01:09

coder623


You could use something like One-JAR to package your Java application together with its dependency into a single executable Jar file (One-JAR uses a custom classloader to make JARs nesting possible).

like image 45
Pascal Thivent Avatar answered Sep 26 '22 01:09

Pascal Thivent