Is it possible to use the external terminal when running a Java program through Netbeans?

Asked

Viewed 567 times

0

What I mean is, I can switch to getting Netbeans output out on Linux bash or Windows cmd instead of using the internal Netbeans application console?

2 answers

1

Assuming your class is an executable class, has a main method, navigate the terminal to the directory your class is in, then type:

// command to compile

javac Suaclasse.java

// Command to execute

java Suaclasse

Example:

    public class SuaClasse { 
        public static void main(String[] args){ 
           System.out.println("Hello World Pelo Terminal =D"); 
        } 
     }

Using the terminal:

    mac@pc:~$ javac SuaClasse.java
    mac@pc:~$ java SuaClasse
    Hello World Pelo Terminal =D

1


Not only is it possible but it’s super easy, as long as you’re with your environment variables (path) well configured. Also, for smaller applications I consider even easier (I only have problems generating the .jar[laughter]).

Example class:

public class MinhaClasse{
    public static void main(String[] args){
        System.out.println("Hello, world");
    }
}

In the CMD:

c\> javac MinhaClasse.java
c\> java MinhaClasse.class
Hello, world

In the terminal:

user@Desktop:~$ javac MinhaClasse.java
user@Desktop:~$ java MinhaClasse.class
Hello, world
  • 1

    And for larger applications? with multiple classes and use of JPA/Hibernate, would it be feasible to use a command line? an application to map the Objects and display the log output in the terminal

  • 1

    good question, Lucas Actually, no, in such cases it is best to use the IDE

  • The bigger the program, the more complex, and the more difficult it is to keep all files synchronized. Even in C/C++ programs, where it is customary to use a text editor and the terminal, the IDE starts to prove advantageous from a certain complexity.

  • 1

    In my opinion, the easiest of the Java IDE is to already separate the sources from the classes, and to export everything to one .jar automatically (plus a matter of practicality). But there are people who do not dispense with the combination terminal + text editor, and, for these, tools such as Atom editor, Sublime Text or Vi/Vim have hundreds of plugins that make development more practical and simple

  • I get it, I will look more about these editors. If you recommend something (especially some plugin for VIM), I will be grateful, thank you

  • 1

    Dude, I would recommend Atom, because it has a built-in plugin database, which makes it really easy to use, and direct connection to Git systems. From Vim, I don’t know much (I’m not a big fan, I find it hard to use).

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.