Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Java program through the terminal in IntelliJ

I know how to run and compile a basic Java program in the terminal using java and javac.

I also know how to run and compile a Java program using IntelliJ.

However, how do you run a program in an IntelliJ project using the terminal.

So far all my classes is compiled to a "out/production/myproject" folder by default in Intellij. So far I have tried the following command in the above folder:

java Main

However for some reason it says:

Error: Could not find or load main class Main
like image 373
Yahya Uddin Avatar asked Feb 10 '23 09:02

Yahya Uddin


1 Answers

When you run a program in Intellij, in the run window (bottom panel) the very first line is what intellij terminal command. The line usually is shortened like this:

/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java...

If you click on it, it will show you full command that Intellij runs.

like image 122
almeynman Avatar answered Feb 15 '23 11:02

almeynman