How to set logger when calling ant target from java

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

I wrote Java code to do this ...

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 someone tell me how to set up a registrar using the 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) 
+4
source share
1 answer

You must add your Logger to Project using addBuildListener, ant provides several implementations that also implement BuildLogger

so

 project.addBuildListener(new DefaultLogger()); 
or whatever your registrar should be (as long as it implements the BuildListener ), it should do the trick
+1
source

Source: https://habr.com/ru/post/1441487/


All Articles