Posted tagged ‘command line’

Ant + JavaFront: start Ant tasks from the command line

7. November 2008

Reading the blog Converting maven pom to ivy I asked myself, why it should not be possible to start Ant tasks from the command line.

Stefan on the other side was bored always to here that Ant relies on XML and he presented a way for writing Buildfiles in plain (annotated) Java using JavaFront, a library in Ants sandbox.

Ant provides a way to override the class to start by providing an implementation of AntStart and specifying that class by -main option. So I wrote a new start class which parses the command line parameters and executes that task. The first parameter is the taskname and following parameters are attributes with their values. (There is no support for nested elements yet.)

public class TaskExec implements AntMain {

public void startAnt(String[] args, Properties additionalUserProperties, ClassLoader coreLoader) {
Map attributes = new Hashtable();

// Analyzing the command line arguments
String taskname = args[0];
for(int i=1; iant -lib build\classes -main org.apache.ant.javafront.TaskExec echo message „Hello World“

Other examples are in the launcher script.


Long time ago …

19. Juni 2008

My last commit to Args4J was long time ago. But I was happy, that my environment works – and also my knowledge about the project itself 😉 And the pause was fine because I startet a new try to implement the setting of Map-entries …. with success. Now you can have a bean with

@Option(name="-map") java.util.Map map;

and set the values from command line via

java MyApp -map key1=value1 -map key2=value2