![]() ![]() In this example, I create just one option, arbitrarily called alpha: //define options You then set whether the option is required or not, and finally add the option to the options object, which contains all of your options. Next, define your individual options by listing a short option, a long option, a default Boolean value, and a help message. Use the Option (singular) class to create option objects and the Options (plural) class to help keep track of all the options you've created in your project.įirst, create a group for your options, and call it options according to convention: //code ![]() The first thing you must do to parse options is to define the valid options your application can accept. For this simple option parsing example, you can populate a file called Main.java with the standard minimal code: package To use the commons-cli library in your code, you must import it. The only required JAR is the commons-cli-X.Y.jar (where X and Y are the latest version numbers.) Add that JAR to your project, either manually or in your IDE, and then you can use it in your code. If you're managing libraries manually, you can download the latest release from the Apache website. If you're using a project management system like Maven and an IDE, you can install the Apache Commons CLI library in your project properties (such as pom.xml or a configuration screen in Eclipse or NetBeans). My favorite is the Apache Commons CLI library, called commons-cli for short. There are several ways to parse options in Java. ![]() Free online course: Developing cloud-native applications with microservices architectures. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |