0

I wrote an ant org.apache.tools.ant.BuildListener that does stuff if the build fails. I can use it from the command line with ant -listener org.smottguyz.antlisteners.SimpleListener build_all. But when I use the NetBeans IDE, there is no apparent way to specify a -listener option.

Is there a way to specify an additional build listener with ant (or NetBeans) properties, settings or configuration somewhere?

EDIT. It turns out this is pretty NetBeans specific, because, for whatever reason, NetBeans disables most of the approaches that work for most ant configurations. So Is it possible to specify logger for ant inside build.xml? is relevant, but not an answer :(

Thanks!

Community
  • 1
  • 1
Charlweed
  • 1,517
  • 2
  • 14
  • 22
  • 1
    see that answer => http://stackoverflow.com/a/12590361/130683 for a similar question – Rebse Sep 22 '15 at 20:18
  • .. in IDE - i use Eclipse - search for something like 'Run as ant' and add -listener ... as argument – Rebse Sep 22 '15 at 20:26
  • .. for Netbeans it might work like that => http://wiki.netbeans.org/FaqAntParameters – Rebse Sep 22 '15 at 20:36
  • possible duplicate of [Is it possible to specify logger for ant inside build.xml?](http://stackoverflow.com/questions/5721513/is-it-possible-to-specify-logger-for-ant-inside-build-xml) – Chad Nouis Sep 23 '15 at 14:31

1 Answers1

0

The short answer, is that with NetBeans 8.0, you can't use any normal technique. NetBeans ant does not use the platforms environment variables, so ANT_OPTS does not work, though it should. Also, nb_ant ignores ~/.ant/antlib, and even adding jars to foo/NetBeans 8.0.2/extide/ant/lib does not work. I'm filing this as a bug, but I expect it will be fruitless.

Anyway, you CAN edit a build file, and add a custom task that installs a custom listener. But you must also add the jar for your task+listener to NBs ant classpath in the correct NB dialog. So I created a tiny class:

public class Installer extends Task {

    @Override
    public void execute() throws BuildException {
       getProject().addBuildListener(new SimpleListener());
    }

}

and in my build.xml

<taskdef name="installListener" classname="org.smottguyz.antlisteners.Installer"/>
<installListener/>

The add the jar in the dialog "Options/Java/Ant/Classpath:"

Pretty annoying actually. Anyway, using scriptdef like on Josef Betancourt's blog post buys nothing in this case.

Charlweed
  • 1,517
  • 2
  • 14
  • 22