I have an existing java command-line program, that takes a bazillion of arguments and parses them using excellent args4j.
I now want to make a maven plugin mojo that will run the Java code contained in this application.
As of now, I’ve tried the basic way : replicating each and any command line argument into a mojo parameter. Bu I find this exceptionnally boring and error-prone, as maven mojo javadoc annotations are far less complete and integrated than can be args4j annotations.
So, using maven 3, is there a better way to have my executable run as a maven mojo ?
Oh, please don’t talk me about exec-maven-plugin, as I find it far too limited in that case (my executable will have to be run using a mix of project settings and user profile ones, and I guess simply calling maven-exec-plugin won’t do the trick).
Although @khmarbaise’s answer is perfectly true on a general point of view, I would like to extend it a little.
My standalone command-line application uses args4j, but I think the process can be fairly well copied using Commons CLI or (even more) JCommander which relies on the same command line annotations in a main bean.
So, what I’ve done is a maven mojo that, using introspection, get the list of main bean command line arguments.
For each of these arguments, I expect a property to be present in the project/settings infos. If this property is present, I build a fake command line using the option and the associated finally.
Once I have browsed all options (stored as maven properties), I can use args4j to fill my bean, then run this bean using its main command.
i think this approach could be quite well generalized, provided your application has a set of flags and a no-args
run()method.