put Java JARs on a diet, and load maven modules as needed (original) (raw)

News:

diet4j, noun

  1. A principled plan to limit ingestion to only the rightfoods JARs instead of living a life of bloat oversized, all-but-the-kitchen-sink JARs and WARs.
  2. An assembly of all the notables modules needed (and no more) in a particular place and time tomake important decisions run a Java application.

So what is diet4j?

diet4j lets you distribute your Maven modules as you built them: one at a time. No need for gigantic JARs or WARs that bundle a gazillion libraries.

When you run an application, diet4j automatically assembles all required modules into a running executable (or web app). It's like Maven at run-time.

It currently works for command-line applications, and Tomcat web applications.

The old way:

java -classpath this.jar:and-this.jar:and-that.jar:and-i-forgot-something.jar:and-lets-bundle-this-too-just-in-case.jar:and-five-more-miles-of.jar

or

java -jar BLOAT.jar

The diet4j way:

diet4j my-project

where my-project is the name of your top-level Maven project. Regardless how complicated its dependencies might be, diet4j will pull in all dependent module JARs at run-time — just like Maven does at compile time. And it uses the pom that maven already packages with the JAR, so you have to do basically nothing to get your code ready for diet4j.

(If you don't like our shell script, you can sayjava -jar diet4j-cmdline-VERSION.jar my-project instead; it does the same thing.)

Why is this a good idea?

Some people like gigantic JARs and long build times. If you don't, diet4j lets you:

How to install

Getting the code is easiest right now with git:

git clone https://github.com/diet4j/diet4j.git cd diet4j mvn install install -m755 diet4j-cmdline/bin/diet* ~/bin/

(This is for Linux)

Demo apps

Get them:

git clone https://github.com/diet4j/diet4j-examples cd diet4j-examples mvn install

Run example 1:

DIET4J_REPO=$HOME/.m2/repository diet4j org.diet4j:diet4j-examples-one some rand/some text

This is what happened:

To learn more, we suggest you look at thecode for the examples on Github.

What else can diet4j do?

Platforms

This has been tested on Linux and OSX, but should run on Windows as well.

License

Apache 2.0, a liberal open-source license.