Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Java application that downloads its own dependencies

I'm interested in how to distribute a Java application that has a lot of dependencies (specified in a pom.xml in Maven).

Obviously it would be possible to just package everything in one big .jar file. However that seems wasteful, since an update of the application would require sending a new copy of all the dependencies as well.

So I'm looking for a way of distributing the app that does the following:

  • Only includes the core application in the main .jar file
  • Downloads dependencies as needed when the .jar file is run
  • Keeps copies of the dependencies locally, so that if an application update is distributed the dependencies don't need to be downloaded again

What's the best way of achieving this?

like image 579
mikera Avatar asked Dec 17 '11 20:12

mikera


2 Answers

Can you just use Maven, with something like described at Maven Run Project ?

This is how I have some of my own applications setup within my own network. I've never needed to worry about messing with the classpaths or downloading / providing dependencies for programs setup like this for a long time. This approach also meets all of your criteria.

like image 130
ziesemer Avatar answered Nov 20 '22 00:11

ziesemer


you can distribute your file using the web start technology (aka distribute a jnlp file). i believe this will handle most of this functionality for you, including updatability.

like image 21
jtahlborn Avatar answered Nov 20 '22 00:11

jtahlborn