MicroBean Main

This is the fifth 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 CDI Utilities.  The next post covers MicroBean Jersey Container Grizzly HTTP CDI Integration.

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

MicroBean Main provides a public static void main(String[]) method that you can use in your CDI 2.0 Java SE applications.  It is staggeringly simple.  It starts a CDI container, making the command line arguments available to the CDI environment in a portable fashion, and then stops the container.

To install MicroBean Main, place it on the classpath.

That doesn’t sound like much, but as I’ve written previously, that, coupled with the event mechanism that CDI defines that notifies CDI beans when the container is started and stopped, provides a very useful mechanism for integration.  Basically, you don’t have to write your own public static void main(String[]) method or rely on an application server for a CDI environment to be made available to your CDI bean.  If your CDI bean observes the initialization of the application scope context, like, perhaps, this:

private final void onStartup(@Observes @Initialized(ApplicationScoped.class) final Object event) {
  // Here is your "main" code.
}

…then when MicroBean Main‘s Main#main(String[]) method is run your observer method will be invoked.  See my prior post on eager startup for more.

In the next post, we switch gears slightly and talk about Jersey and Grizzly.

Advertisements

3 thoughts on “MicroBean Main

  1. Pingback: MicroBean CDI Utilities | Blame Laird

  2. Pingback: MicroBean Jersey Container Grizzly HTTP CDI Integration | Blame Laird

  3. Pingback: MicroBean Commons CLI | Blame Laird

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s