Use an external terminal

How can I get Netbeans to run my Java project inside the system terminal, and not its embedded terminal?

I looked around and apparently should have done Project Properties->Run->Console Type , but this, unfortunately, was removed from the project’s configuration panel at some point in history.

Every other thread that I can dig on the Internet addresses this issue - predictably - there are no answers.

I know that I can run the jar file from the command line, but an integrated solution would be useful.

I am using Netbeans 7.

+4
source share
1 answer

I'm not sure if this can be done for the Ant project, but it can be done for the Maven project.

  • Create a Maven Project. File → New Project. Select the Maven category and the Java Application project type. Click Next and then Finish to accept the project defaults.
  • Add a main class with the public static void main (String args []) method. Expand the source packages in the Projects window. Choose any package. Right-click → New → “Java Class”.

Add something to wait for the exit to exit or your terminal will exit without your 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 a project in the project window. Right click for popup. Select "Properties." Select the Run category. Click the Browse button next to the main class and select Main Class.
  • Run the project once in normal mode using the green triangle in the toolbar, the Run-> Run Project menu, or F6.
  • In the project window, specify the "Project Files" node. Double-click "nbactions.xml".
  • Change the properties for the run action. Change the executable to your terminal and add the appropriate arguments 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. Now it should be open in the external terminal.

Note. Here I gave the same answer: display netbeans java output on command line

0
source

Source: https://habr.com/ru/post/1495681/


All Articles