A pretty standard requirement for any Java server-side application is a command line parser
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
TargetInstanceName=Payload[1];
A quick google search shows a number of command line parsers. The top hit is Apache Commons CLI. After 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)){
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.
Comments
Post a Comment