简体   繁体   English

命令提示符中的Javac命令不执行文件

[英]Javac command in command prompt does not execute file

Ok I am new to Java and was trying to run a java program from the command prompt (because Sublime compiles and runs in it's little thing but doesn't allow for user inputs and stuff). 好的,我是Java的新手,并试图从命令提示符下运行Java程序(因为Sublime可以在其中编译和运行是一件小事,但不允许用户输入和输入东西)。

I set the command prompt to the folder which I have my file which is called Learner.java. 我将命令提示符设置为我的文件名为Learner.java的文件夹。

C:\Users\jonat>cd C:\Users\jonat\Desktop\Projects\Java

I have set a path for my JDK bin in my environment variables and created a JAVA_HOME variable with a value to the JDK bin (which some other post suggested). 我已经在我的环境变量中为我的JDK bin设置了路径,并创建了一个JAVA_HOME变量,该变量具有JDK bin的值(一些其他文章建议)。

Before I go into the issue, this is my code: 在深入探讨此问题之前,这是我的代码:

class Learner {
  public static void main(String[ ] args) {
    System.out.println("Jonathan's Project");
  }
}

As you can see, it is a simple print project with "Jonathan's Project" as the output. 如您所见,这是一个简单的打印项目,输出为“乔纳森的项目”。 I have already tested this in Sublime 3 and it compiles and prints. 我已经在Sublime 3中对其进行了测试,并且可以编译和打印。

HOWEVER, when I call upon the program in cmd prompt, it just runs for a second or so and then skips a line and starts a new command line. 但是,当我在cmd提示符下调用该程序时,它仅运行一秒钟左右,然后跳过一行并开始一个新的命令行。 No "Jonathan's Project" prints which is weird because the cmd prompt shows no error and it acts like it ran the program but nothing was run... 没有打印“ Jonathan's Project”,这很奇怪,因为cmd提示符未显示任何错误,并且它的行为就像是在运行程序,但未运行任何内容...

javac is to compile the program. javac是要编译的程序。 To run the program, use the java command. 要运行该程序,请使用java命令。 You need to compile before running the program. 您需要在运行程序之前进行编译。

Also, with javac , you need to write javac Learner.java , and with java you only need java Learner . 另外,对于javac ,您需要编写javac Learner.java ,而对于java ,则仅需要java Learner

To learn more about compilation and execution check out this link: https://www.geeksforgeeks.org/compilation-execution-java-program/ 要了解有关编译和执行的更多信息,请查看以下链接: https : //www.geeksforgeeks.org/compilation-execution-java-program/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM