How to display the NetBeans ide java program console output onto the windows command line output? please help as I am new to this...thanks in advance here I must execute the program from NetBeans but only the output must be displayed on my windows command line.
Asked
Active
Viewed 4,004 times
2
-
no not running on command prompt but diplaying the output of NetBeans program run in NetBeans onto command prompt – adibro500 Aug 09 '15 at 09:47
-
when you run it in cmd you can see the output in cmd . – Madhawa Priyashantha Aug 09 '15 at 09:49
-
but I don't want to run in cmd but I want to run in Netbeans and see the output only on cmd. – adibro500 Aug 09 '15 at 09:56
-
@user4800039 Your first comment should be an edit to your question. Use [edit button](http://stackoverflow.com/posts/31902866/edit). – VP. Aug 09 '15 at 10:10
-
1Can you explain why you need to run it from one place, but send output to another? Why can't you run and see output both in the same place? You can do both in Netbeans and you can do both in cmd. – takendarkk Aug 09 '15 at 10:28
-
1@user4800039 Explain why want this? – Rahul Aug 09 '15 at 12:52
-
@takendarkk I'd explain it for him to you as I need this too myself: one want to run his project form NetBeans yet seeing output in CMD instead of OutputWindow because OutputWindow doesn't support some important things, like one-line-output-update (aka one line DOS progressbar) whereas CMD does (it is really important feature for me as I'm trying fine tuning it so I need to see what it does), secondly with bigger projects running it from NB is much faster than waiting for compilation and then running it from command line (using bat as I do, for example) and going back to NB for every edit..no – qraqatit Jan 13 '20 at 18:48
1 Answers
1
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.

WillShackleford
- 6,918
- 2
- 17
- 33