0

I have seen few examples where ANT is run though java code. Here is one such example. Here DefaultLogger is being used:

Project p = new Project();
.
.
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);

However I want to use log4j. I have mylog4j.xml already defined in the application. I want to use same XML for configuring ANT LOGGER ("org.apache.tools.ant") and want to use this logger. Can someone tell me how to do so in java code?

Note: I have done something like:

org.apache.tools.ant.listener.Log4jListener log4j = new Log4jListener();  
p.addBuildListener(log4j);

But I don't know how to specify the log4j config xml file path to ant launcher.

Community
  • 1
  • 1
keenUser
  • 1,279
  • 3
  • 16
  • 33

1 Answers1

0

There is no way to specify the location of your file using the ANT's API. However, you can use the class org.apache.log4j.xml.DOMConfigurator. e.g.:

DOMConfigurator.configure("/path/to/mylog4j.xml");
Project p = new Project(); 
p.addBuildListener(new Log4jListener());

See also Listeners & Loggers in the Apache Ant 1.9.4 Manual.

Paul Vargas
  • 41,222
  • 15
  • 102
  • 148