Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

This is an example project to test and demonstrate how to create self contained (single binary) CLI in Java.

I know, I know. Why Java? Well, a lot of people that don't, but definitely should write CLIs have Java as their primary language. They should write CLIs to make their life easier. It's time to stop with all the Maven/Gradle/Whatever plugins that shoehorns functionality that have nothing to do with builds and releases into it.

In additiion:

  • People seems more used to writing tests in Java. Yes, you should have automated tests for your CLI.
  • You can create single distributable binary
  • It's cross platform
  • It starts up much faster than I feared. ;)

You can do it. Just write a CLI. ;)

These are of course traits you can find other places, but I really wanted to make it easy in Java too. ;)


To build/test this project you'll need:

  • JDK (8 and above)
  • Maven

Running the resulting code requires a JRE installed.

What's used

There are other libraries used as well, but they are only for demo purposes.

NOTE: The Shade plugin might get you into problems with some libraries. A friend of mine pointed me in the direction of Capsule which looks promising. You might want to look into that if Shade gives you problmems. There are some minor drawbacks to how it does stuff, but I'll certainly keep it at hand.

Distribution of the binary

Hopefully you release your binaries from Maven to some kind of repository. That makes it available over HTTP so I usually do something like:

curl http://myrepo/org/my/group/artifact/version/artifact-version.jar > ~/bin/mycli && chmod u+x ~/bin/mycli

Awesomeness with completion

Since DocOpt is a machine readable format you can even generate Bash completion for your command automatically. Have a look at this link to see how:


NOTE: As this is Java you'll of course need a JRE installed. Nothing will work witout it. :)

You can build and run locally (requires all the usual Maven, JDK things):

mvn clean install && ./target/executable-json-util-1.0-SNAPSHOT.jar

Or you test it easily like this (just need the JRE):

curl > ~/bin/json-util && chmod u+x ~/bin/json-util

You probably shouldn't download random binaries off the internet and run them, but if you like to you can. :)


Example code for how to create a single binary CLI in Java.






No releases published


No packages published