Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats best way to package a Java Application with lots of dependencies?

I'm writing a java app using eclipse which references a few external jars and requires some config files to be user accessable.

  1. What is the best way to package it up for deployment?

  2. My understanding is that you cant put Jars inside another jar file, is this correct?

  3. Can I keep my config files out of the jars and still reference them in the code? Or should the path to the config file be a command line argument?

  4. Are there any third party plugins for eclipse to help make this easier? I'm using an ant build file at the moment but I'm not sure I know what I'm doing.

  5. Is there an equivelent of the deployment projects in Visual studio, that will figure out everything you need and just make an installer? I've used install4j before, and it was powerful if no where near as automated as .Net deployment projects.

Cheers.

like image 681
Omar Kooheji Avatar asked Nov 19 '08 14:11

Omar Kooheji


2 Answers

There is no one 'best way'. It depends on whether you are deploying a swing application, webstart, applet, library or web application. Each is different.

On point 2, you are correct. Jar files cannot contain other jar files. (Well, technically they can, its just that the inner jar file won't be on your classpath, effectively meaning that jar files do not contain jar files).

On point 3, you certainly can reference config files outside the jar file. You can typically reference a config file as a file or a resource. If you use the resource approach, it typically comes from the classpath (can be in a jar). If you use a file, then you specify the filename (not in a jar).

In general, most Java developers would use Apache Ant to achieve deployment. Its well documented, so take a look.

like image 194
JodaStephen Avatar answered Nov 10 '22 18:11

JodaStephen


(1) An alternative to ant that you may wish to consider is maven.

A brief intro to maven can be found here.

For building a JAR, maven has the jar plugin, which can automate the process of ensuring all dependent jars are listed in your jar's manifest.

If you're using eclipse, then download the maven integration as well.

(2) Another alternative is to use OneJar (disclaimer: haven't tried this myself).

like image 41
toolkit Avatar answered Nov 10 '22 20:11

toolkit