I wish to be able to do the following under Windows (Windows 7):
Why do I want this? To be sure that it works, and to be able to send a Control-C to the terminal/console.
I think it could be achieved via Ant, but please help me on how to do this.
You can do this by extending NetBeans' build script. To do that, do the following:
nbbuild.xml file in the directory with the name of your project.Add the following code to it:
<target name="-post-jar">
<exec executable="cmd.exe" dir="${dist.dir}">
<arg value="/k"/>
<arg value='start "MyApp" java -jar ${dist.jar}'/>
</exec>
</target>
Now when you build your project the -post-jar target will be called once NetBeans is finished with the build. This will start a commandline window to run your project. As an alternative you could also override the run target. An example on how to do that is inside the nbbuild.xml file.
Note that you have to use the start command, otherwise the console window won't be visible (at least I don't know of any other way).
This also assumes that you have a self-executable jar file that can be started using java -jar .... If that is not the case you will need to assemble the full classpath to be passed to the java command.
Some more information about customizing NetBeans' build process can be found in the online help: http://docs.oracle.com/cd/E40938_01/doc.74/e40142/create_japps.htm#CHDDAHEB
Having said all that: to verify that your application works correctly, it would be a much better choice to write proper unit tests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With