I am not sure this can be done for an Ant project but it can be done for a Maven project.
- Create a Maven Project. File -> New Project. Select Category "Maven" and Project Type "Java Application". Click Next and then Finish to accept project defaults.
- Add a Main class with a public static void main(String args[]) method. Expand Source Packages in the Projects window. Select any package. Right-click -> New -> "Java Class".
Add something to wait for output before exiting or your terminal will exit without your having time to view the output.
public static void main(String[] args) {
System.out.println("hello");
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
}
- Select the project in the projects window. Right-click for pop-up. Choose Properties. Select category "Run". Click the Browse button next to Main class and select the Main class.
- Run the project one time normally with the green triangle on the toolbar, menu Run-> Run Project or F6.
- Expland the "Project Files" node in the projects window. Double-click "nbactions.xml".
- Change the Properties for the "run" action. Change executable to your terminal and add the appropriate flags and java to the arguments.
eg. From :
<properties>
<exec.args>-classpath %classpath wshackle.mavenproject2.Main</exec.args>
<exec.executable>java</exec.executable>
</properties>
to :
<properties>
<exec.args>-x java -classpath %classpath wshackle.mavenproject2.Main</exec.args>
<exec.executable>gnome-terminal</exec.executable>
</properties>
or for Windows:
<properties>
<exec.args>/c java -classpath %classpath wshackle.mavenproject2.Main</exec.args>
<exec.executable>cmd</exec.executable>
</properties>
- Save and close this file.
- Run the project. It should now open up in an external terminal.
Note: I provided the same answer here:
display netbeans java output terminal on the command line