Ant in Netbeans: overriding run target doesn't

2019-08-05 01:23发布

问题:

I am trying to override the "run" target in a Netbeans project. What I'm doing is editing the file build.xml:

<project name="Test123" default="default" basedir=".">
    <import file="nbproject/build-impl.xml"/>

    <target depends="init,compile" name="run">
        <echo>AAAAAAAAAAAAAAAAAAAAAA</echo>
    </target>
    <target depends="init,compile-single" name="run-single">
        <echo>AAAAAAAAAAAAAAAAAAAAAA</echo>
    </target>
</project>

I tried to override both "run" and "run-single", but both things doesn't change anything. When pressing F6, the project's Main class is executed as before. The test message (AAA...) is not printed.

EDIT:
Created a bug report for Netbeans.

回答1:

The solutions is, as mentioned in the answer to my bug report, to turn off compile-on-save.



回答2:

That seems to be correct. Do not use F6, try to run the "run" target from the context menu on the build.xml file. That should work.

I think the default key binding for F6 is "Run Main Project" and that does not the same as "run".