如何在命令提示符下运行java程序,由intellij创建 [英] How to run java program in command prompt,created by intellij
问题描述
如何在命令提示符下运行我的Java程序,我的项目是在Intellij中创建的,我在命令提示符下运行它时遇到困难...在创建项目时没有使用Intellij,我可以运行java程序命令提示符。
How do I run my Java program in command prompt, my project was created in Intellij, and I am having difficulties running it in the command prompt...without using the Intellij in creating project,I can run the java program in command prompt.
我是这样做的。
java myjava ->this would work.
但由Intellij创建的项目,这是路径。
but the project created by Intellij,this is the path.
C:\myjava\sampl1\src\com\myexample\test>
java myjava -> Error: Could not find or load main class myjava
但我在该目录中。
提前谢谢。
推荐答案
三个问题:
-
您必须为
java $ c指定完全限定的类名(即包含包名) $ c>命令。看起来你的
myjava
类在一个包com.myexample.test
中。所以它的完全限定名是com.myexample.test.myjava
。
You have to specify the fully qualified class name (that means including the package name) to the
java
command. It looks like yourmyjava
class is in a packagecom.myexample.test
. So its fully qualified name iscom.myexample.test.myjava
.
当你运行 java
命令您必须位于包层次结构的基础上(或将该目录放在类路径上)。
When you run the java
command you have to be in the directory that is at the base of the package hierarchy (or put that directory on the classpath).
您正在使用 src
目录,其中包含 .java
源文件,但 java
命令需要编译 .class
文件,因此您需要使用项目的输出目录。它在您的项目中的位置将取决于您的IDE和配置,但它将包含与 src
内部相同的结构,但 .class $除外c $ c>文件而不是
.java
文件。
You're using the src
directory, which contains .java
source files, but the java
command expects compiled .class
files, so you need to use the project's output directory. Its location in your project will depend on your IDE and configuration but it will contain same-named structure as inside src
, except with .class
files instead of .java
files.
在您的情况下,导航至:
In your case, navigate to:
C:\myjava\sampl1\out\production\
然后运行:
java com.myexample.test.myjava
这篇关于如何在命令提示符下运行java程序,由intellij创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!