Yahya Uddin
Yahya Uddin

Reputation: 28921

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

Upvotes: 4

Views: 18047

Answers (2)

almeynman
almeynman

Reputation: 7428

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.

Upvotes: 8

user4668606
user4668606

Reputation:

You'll have to specify the classpath before calling java Main.

Upvotes: 0

Related Questions