如何在 IntelliJ 中通过终端运行 Java 程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29782345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run Java program through the terminal in IntelliJ
提问by Yahya Uddin
I know how to run and compile a basic Java program in the terminal using java
and javac
.
我知道如何在终端中使用java
和运行和编译基本的 Java 程序javac
。
I also know how to run and compile a Java program using IntelliJ.
我也知道如何使用 IntelliJ 运行和编译 Java 程序。
However, how do you run a program in an IntelliJ project using the terminal.
但是,如何使用终端在 IntelliJ 项目中运行程序。
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:
到目前为止,我的所有类都默认编译到 Intellij 中的“out/production/myproject”文件夹。到目前为止,我已经在上面的文件夹中尝试了以下命令:
java Main
However for some reason it says:
但是出于某种原因,它说:
Error: Could not find or load main class Main
回答by almeynman
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:
当您在 Intellij 中运行程序时,在运行窗口(底部面板)中,第一行是 Intellij 终端命令。该行通常缩短如下:
/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.
如果单击它,它将显示 Intellij 运行的完整命令。
回答by Paul
You'll have to specify the classpath before calling java Main
.
您必须在调用之前指定类路径java Main
。