Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #38892

Re: Preferred way to distribute application

From Patrick Roemer <sangamon@netcologne.de>
Newsgroups comp.lang.java.programmer
Subject Re: Preferred way to distribute application
Date 2019-04-10 16:22 +0200
Organization news.netcologne.de
Message-ID <q8ku6o$ur$1@newsreader4.netcologne.de> (permalink)
References <q8fb8g$243$1@gioia.aioe.org>

Show all headers | View raw


Responding to Graeme Geldenhuys:
> What is the preferred way to distribute a console java application?
> 
> For example:
> 
>   1.  Package everything into a single JAR with embedded jar
>       dependencies.

This requires some kind of Main wrapper for custom class loading, since
nested jars cannot be handled by the default class loader(s). At least
that was the status the last time I checked. Build tools that support
this option will automagically generate such a wrapper for you, and I
wouldn't expect any problems from these, but it does add some additional
complexity under the hood.

>   2.  Package application into a single JAR but don't embed any
>       dependency jars. Have the dependency jars as a separate
>       downloadable archive.

I certainly wouldn't recommend a separate download. However, you could
zip your jar together with the dependency jars and set up the proper
relative classpath in your jar's manifest. This is probably the most
brittle and pedestrian option, but it might work ok.

>   3.  Package everything into a single JAR with related
>       dependencies but dependencies are unpacked - seems to
>       produce a slightly smaller final jar.

That's probably the most common option. As long as you're not planning
to do the packaging manually (you shouldn't!), I don't think the choice
between 1 and 3 makes a huge difference.

If you're worried about jar size, there's tools like ProGuard that
specialize on this aspect.

> At the moment I don't have a lot of dependencies, but you never know
> what the future of the project might dictate.
> 
> Not sure if it matters, but I'm using Eclipse to build the final JAR. In
> the future I would like to let Maven do this for me so I can automate
> builds.

Just use whatever your build tool supports out-of-the-box. In the case
of Maven, that's probably the assembly plugin with jar-with-dependencies
settings, resulting in option 3 above. In the unlikely case of running
into name clashes in your dependencies, move on to the shade plugin.

Best regards,
Patrick

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Preferred way to distribute application Graeme Geldenhuys <graemeg@example.net> - 2019-04-08 12:28 +0100
  Re: Preferred way to distribute application Joerg Meier <joergmmeier@arcor.de> - 2019-04-08 14:46 +0200
    Re: Preferred way to distribute application Graeme Geldenhuys <graemeg@example.net> - 2019-04-10 10:29 +0100
  Re: Preferred way to distribute application Patrick Roemer <sangamon@netcologne.de> - 2019-04-10 16:22 +0200

csiph-web