Posts

Showing posts from September, 2017

Java Command-Line Interfaces (Part 17): jw-options

Image
The JavaWorld article Processing command line arguments in Java: Case closed by Dr. Matthias Laux introduces a simple Java-based library for processing command-line arguments that I'll refer to in this post as jw-options . The referenced article provides background information on why certain design decisions were made in construction of the Options class. The "Conclusion" of the article describes the advantage of using the accompanying class and library: "This article describes a Java class that allows for the convenient processing of command line options for Java programs. The structure is flexible enough to handle even complex situations, while at the same time offering an API that allows for the definition of acceptable command line syntax with limited coding effort." The "library" introduced by this JavaWorld article consists of three Java classes: Options , OptionData , and OptionSet . This is demonstrated in the following screen snapshot th...

Java Command-Line Interfaces (Part 16): JArgp

Image
The Java-based command line argument processing library covered in this post was the featured library of an IBM developerWorks article Java programming dynamics, Part 3, Applied reflection (this 2003 article was "archived" in 2016, but is still available for PDF download ). The library, called JArgp ( Java Command Line Argument Processing Library ), is defined on its main web page as "a library for processing command line arguments in Java." This page adds, "Unlike most other libraries of this type, JArgp uses reflection to store actual values directly to fields in the target application object." JArgp 1.0 is featured in this post. JArgp is a minimalistic library as shown by the small number of classes in the JArgp JAR. The "definition" stage is accomplished in JArgp via specification of an array of ParameterDef instances. Custom classes can be written to extend the ParameterDef class, but I'll be able to use two provided extensions...

JDK 9 Released Today

The big news in Java today is, of course, the release of JDK 9 in General Availability . Mark Reinhold starts his message JDK 9: General Availability with the statement, "I'm pleased -- nay, thrilled! -- to announce that JDK 9 is now Generally Available." The Reinhold post adds that in addition to Jigsaw, there are "many other excellent additions and improvements." He lists them with links that are reproduced here: JDK 9 Features Improved Process API HTTP/2 Client (incubating) Variable Handles JShell Read-Eval-Print Loop Javadoc Search Linux/AArch64 Port Marlin Graphics Renderer Collection Factories Enhanced Deprecation Linux/s390x Port Ahead-of-Time (AOT) Compilation It will be interesting to see what people learn and share from using JDK 9 over the next several months. We've already seen numerous resources based on early releases of JDK 9, but I'd expect usage and consequential lessons learned to pick up with JDK 9 in General Availability. Rec...

Java Command-Line Interfaces (Part 15): Jargo

Image
Jargo is defined on its main GitHub page as "a tool to ease the handling of program arguments/options." That page provides a Rationale for another command line processing library when so many others already exist and the top of that list is, "Because type-safety, immutability and readability matters." Jargo's options "definition" stage uses generic typed instances of the Argument class. These instances of Argument are created via static methods on the Arguments class to establish the type and then using builder-style methods to describe the option. This is demonstrated in the next screen snapshot which depicts definition of options for file path/name and verbosity (full code listing is available on GitHub ). "Definition" Stage with Jargo final Argument<String> filePathAndName = stringArgument().description("Path and name of file.") .names("--file", "-f") ...

Java Command-Line Interfaces (Part 14): google-options

Image
The GitHub page for google-options states that google-options is a "command line argument parsing library from the folks at Google (java)." The page goes on to say, "This is the command-line arguments parser from the Bazel Project . The com.google.devtools.common.options package has been split out into a separate jar for general utility." This blog post demonstrates applying google-options to processing command line options from Java code. The example used in this post to demonstrate google-options is similar to the examples used in the earlier thirteen posts in this series on processing command line options in Java. This example supports two options: a required file path/name option expecting a String argument with that path and name and a verbosity option with no argument (its existence enables verbosity). Only the most relevant portions of the code will be shown in this post, but the full code is available on GitHub . The "definition" stage of Jav...