Featured post

Fixed Income Trading: New venues

A simple question came up recently in a conversation – how many new Fixed Income trading venues are there?  I could not think of anywhere th...

Thursday, 7 May 2015

Java Command Line parsers - total cost of ownership?

A pretty standard requirement for any Java server-side application is a command line parser
A quick google search shows a number of command line parsers.  The top hit is Apache Commons CLIAfter implementing it and dealing with the rather unhelpful documentation I decided to write my own.   

Input from the command line will be something like this:
-DTargetUserName=javaloader  -DTargetPassword=XXXXX -DTargetDatabaseName=YYYYY -DTargetServerName=WWWWW -DTargetInstanceName=ZZ -DGetJobsStoredProcedure=pro_sp_NEWLOADER_get_jobs -DLoaderInstanceUniqueName=qqq -DTargetPortNumber=1433

This is received into void main as a string array then parsed and used to populate a configuration class which is used in the code. The parser code just needs to be amended with each new parameter - something like:
   
} else if (Payload[0].equals(nTargetInstanceName)){

TargetInstanceName=Payload[1];
 
For this specific use case the parameters will always require development work to implement the functionality that is commanded by the parameter, so adding two lines of code to a parser is not an onerous task.  This roll-your-own parser is not as feature rich as the Apache Commons CLI but it does the job required. This does lead me to consider the use of third party and/or free and open source libraries.  Think of the time to download the library, read the readme.md and play around with the samples.  Then consider the time needed to regression test new versions and so on.
 
Maybe the use of a third party library is not always right on a true total cost of ownership basis?



No comments:

Post a Comment