2

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).

Riduidel
  • 22,052
  • 14
  • 85
  • 185

2 Answers2

2

The only way is via the mojo parameters cause that's the Maven way in particular for Maven Plugins.

What i missed to define a property file which contains the configuration as an alternative to the mojo parameters. But i think for Maven Plugins the best practice is to have Mojo Parameters.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I'm sorry to un-accept your answer, but I found a better solution and will explain it in a later answer. Please excuse my behaviour. – Riduidel Apr 06 '11 at 08:39
1

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.

Community
  • 1
  • 1
Riduidel
  • 22,052
  • 14
  • 85
  • 185