MicroBean Commons CLI

This is the tenth of a series of posts on some of the personal projects I’ve been working on.  As I hope you’ll see, they all fit together.  The previous post covered MicroBean Maven CDI.  The next post covers MicroBean Launcher.

This post covers MicroBean Commons CLI.  Its website is here, its source code is here and its binaries are available from Maven Central.

MicroBean Commons CLI provides a CDI portable extension that sets up a producer method that produces a CommandLine if there is an Options CDI bean instance in the current CDI container, and if something somewhere makes the command-line arguments available as a String[] qualified with @Named("commandLineArguments") (it just so happens that MicroBean Main does this).

To install MicroBean Commons CLI, place it (and its dependencies) on your classpath.

This means that if your application has a producer method in it that returns an Options, and MicroBean Commons CLI is on the classpath, then you can @Inject a CommandLine anywhere you like, which gives you access to command line option processing.  This, in turn, means that your CDI bean can process command line options easily and intelligently, even though in all likelihood you probably didn’t write the public static void main(String[]) method.  See my post on MicroBean Main for more on this general pattern.

The next post covers MicroBean Launcher, which allows you to link and run a CDI 2.0 Java SE application together out of Maven-addressible artifact coordinates.


Author: Laird Nelson

Devoted husband and father; working on Helidon at the intersection of Java, Jakarta EE, architecture, Kubernetes and microservices at Oracle; open source guy; Hammond B3 player and Bainbridge Islander.

2 thoughts on “MicroBean Commons CLI”

Comments are closed.

%d bloggers like this: