12

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?

mikera
  • 105,238
  • 25
  • 256
  • 415
  • Before somebody suggests that, OSGi seems to be an overkill here, but I believe it has this nice features of downloading and updating bundles on the fly, even without restarting. – Tomasz Nurkiewicz Dec 17 '11 at 20:34
  • This doesn't help you right now, but I thought I would mention that there is work ongoing to resolve this problem on the level of JDK itself. It's called Project Jigsaw and is currently scheduled to be included in JDK 8. Read more about it here: http://openjdk.java.net/projects/jigsaw/ – ivantod Dec 17 '11 at 20:38
  • @ivantod: Three years later. JDK 8 is out. No Jigsaw yet. Still on the roadmap, though. – Thilo Jan 05 '15 at 07:48
  • 1
    @Thilo Yeah I know :( Jigsaw was moved into JDK 9 at some point in late 2013 because they needed more time. However, last November at Devoxx Java conference there was a demo by Paul Sandoz of an actual `javac` that was able to compile modules and all that, so looks like it might make it for JDK 9 finally. But considering that Jigsaw was originally intended for JDK 7 (believe it or not), I'll believe it when I see it. – ivantod Jan 05 '15 at 09:07

2 Answers2

3

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.

Community
  • 1
  • 1
ziesemer
  • 27,712
  • 8
  • 86
  • 94
  • yeah, and possibly a wrapper around maven so that the users won't have to deal with it. pushing updates would just be changing few poms and the maven takes care of the rest. – milan Dec 17 '11 at 21:08
2

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.

jtahlborn
  • 52,909
  • 5
  • 76
  • 118
  • See also the [Java Web Start](http://stackoverflow.com/tags/java-web-start/info) tag info, which includes the above link & 8 more, as well as a 'developer oriented' description of JWS. – Andrew Thompson Dec 18 '11 at 03:25