Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set the logger while calling ant target from java

Tags:

java

shell

ant

I have to call an ant target from java class, currently it is being called from sh script where it sets -logger logger.class

I have written the java code to do so...

Project p = new Project();
        p.setUserProperty("ant.file", buildFile.getAbsolutePath());
        p.init();
        ProjectHelper helper = ProjectHelper.getProjectHelper();
        p.addReference("ant.projectHelper", helper);
        helper.parse(p, buildFile);
        p.executeTarget(TARGET);

Can some one tell me how to set the logger using same code sequence.

error:

Class not found:util.logger.CustomLogger
java.lang.RuntimeException
        at org.apache.tools.ant.Main.createLogger(Main.java:850)
        at org.apache.tools.ant.Main.addBuildListeners(Main.java:795)
like image 649
user1731553 Avatar asked Nov 04 '22 13:11

user1731553


1 Answers

You have to add your Logger to the Project with addBuildListener, ant provides a few implementations which also implement BuildLogger

so

project.addBuildListener(new DefaultLogger());
or whatever your logger jave to be (as long as it implements BuildListener) should do the trick
like image 72
Mathieu Le Tiec Avatar answered Nov 08 '22 04:11

Mathieu Le Tiec