java 如何使用终端/cmd编译java项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36678116/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 01:44:30  来源:igfitidea点击:

How to compile a java project with a terminal/cmd

java

提问by zin

I got tired of using Eclipse because it was too "plain" and "old style". So I moved on to a program called Sublime Text 3 and I used a package named "material theme" which made the program look flat and all nice and stuff.

我厌倦了使用 Eclipse,因为它太“简单”和“老式”了。所以我转向了一个名为 Sublime Text 3 的程序,我使用了一个名为“材料主题”的包,它使程序看起来很扁平,而且一切都很好。

But I wanted to code Java in that but I don't know how to compile stuff without using an IDE and it was not easy to find out but I found out that you could do it through the terminal/cmd of your operating system.

但我想在其中编写 Java 代码,但我不知道如何在不使用 IDE 的情况下编译东西,而且不容易找到,但我发现您可以通过操作系统的终端/cmd 来完成。

But what I don't understand is how I could actually use the javaccommand which means Java Compile and I searched and I didn't find out because I couldn't understand anything that was posted on either YouTube or Stack Overflow because I'm new to this whole terminal/cmd Java Compiling thing.

但我不明白的是我如何实际使用该javac命令,这意味着 Java Compile 并且我进行了搜索但我没有找到,因为我无法理解发布在 YouTube 或 Stack Overflow 上的任何内容,因为我是新手到整个终端/cmd Java 编译的东西。

回答by Gene M

You're almost there buddy!

你快到了,伙计!

Just be sure you have the Java Development Kit (JDK)installed in your system. The JDK provides you the command javac-which you need to compile your .javaprogram files.

只要确保您Java Development Kit (JDK)的系统中安装了 。JDK 为您提供了javac编译.java程序文件所需的命令。

The javaccommand is not that friendly as you think it is. You have to let it know where to find the java file you want to compile.

javac命令并不像您想象的那么友好。您必须让它知道在哪里可以找到要编译的 java 文件。

For example you saved Main.javainside C:\Projects\Javayou must compile it this way javac C:\Projects\Java\Main.java.

例如你保存Main.java在里面C:\Projects\Java你必须这样编译它javac C:\Projects\Java\Main.java

Then you can run your program this way too java C:\Projects\Java\Main

然后你也可以这样运行你的程序 java C:\Projects\Java\Main

As mentioned here... You can find a more detailed explanation to the official tutorial.

正如这里提到的...您可以在官方教程中找到更详细的解释。

回答by Murray

You need to install java JDK which you can find here

你需要安装java JDK,你可以在这里找到

Then you need to right-click on my computer->properties->advanced system settings->Environment variables -> Click on path -> New

然后需要右键我的电脑->属性->高级系统设置->环境变量->点击路径->新建

Then add the path to the bin folder inside the install folder for JDK.

然后将路径添加到 JDK 安装文件夹内的 bin 文件夹。

Then in cmd you can compile with

然后在cmd中你可以编译

javac *.java

inside the directory of your code

在您的代码目录中

回答by Enteleform

  1. Install JDK

    (Make sure your PATHvariable is set up)

  2. Use SublimeText's Build System, which allows you to compile open javadocuments with the Ctrl + Bcommand.

  1. 安装JDK

    确保您的PATH变量已设置

  2. 使用 SublimeText 的Build System,它允许您java使用Ctrl + B命令编译打开的文档。

回答by randominstanceOfLivingThing

You did not install JDK. You need to install JDK which has javac command.

你没有安装JDK。您需要安装具有 javac 命令的 JDK。

Installing JDK on MAC instructions

在 MAC 上安装 JDK 说明

Installing JDK on Windows instructions

在 Windows 上安装 JDK 说明

After installing JDK(Java Development Kit), you can run the command javac -versionon command line and let it show the version that is installed.

安装JDK(Java Development Kit)后,您可以javac -version在命令行上运行该命令并让它显示已安装的版本。