Java 你如何安装JDK?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/998260/
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 do you install JDK?
提问by JD Isaacks
I have eclipse and I can test run java apps but I am not sure how to compile them. I read that I should type javac -version into my cmd.exe and see if it is recognized. It is not. So I went to sun's website and downloaded/installed JDK v6. Yet it still says 'javac' is an unrecognized command. What am I doing wrong?
我有 Eclipse,我可以测试运行 Java 应用程序,但我不确定如何编译它们。我读到我应该在我的 cmd.exe 中输入 javac -version 并查看它是否被识别。它不是。所以我去了sun的网站并下载/安装了JDK v6。然而它仍然说'javac'是一个无法识别的命令。我究竟做错了什么?
Thanks!
谢谢!
UPDATEOK after reading some replies it seems like what I am trying to do is create a .jar file that can be ran on another computer (with the runtime). However I am having trouble figuring out how to do that. This might be because I am using Flex Builder(eclipse), but I added the ability to create java projects as well.
UPDATEOK 在阅读了一些回复之后,我似乎想要做的是创建一个可以在另一台计算机上运行的 .jar 文件(使用运行时)。但是,我无法弄清楚如何做到这一点。这可能是因为我使用的是 Flex Builder(eclipse),但我也添加了创建 java 项目的功能。
Thanks
谢谢
UPDATEOK I do not want to make a JAR file, I am not trying to archive it...the whole point of making a program is to send it to users so they can use the program...THAT is what I am trying to do...why is this so hard?
更新好的,我不想制作 JAR 文件,我不想将其存档……制作程序的全部意义在于将其发送给用户,以便他们可以使用该程序……这就是我正在尝试的要做……为什么这么难?
采纳答案by EdSG
A JAR file can function as an executable, when you export your project as a JAR file in Eclipse (as Michael Borgwardt pointed out) you can specify what's the executable class, that meaning which one has the entry point [aka public static void main(String[] args)
]
JAR 文件可以用作可执行文件,当您在 Eclipse 中将项目导出为 JAR 文件时(正如 Michael Borgwardt 指出的那样),您可以指定什么是可执行类,这意味着哪个具有入口点 [aka public static void main(String[] args)
]
If the user installed the JRE he/she can double-click it and the application would be executed.
如果用户安装了 JRE,他/她可以双击它并执行应用程序。
EDIT:For a detailed explanation of how this works, see the "How do I create executable Java program?"
编辑:有关其工作原理的详细说明,请参阅“如何创建可执行的 Java 程序?”
回答by Daniel Schneller
javac is located in the "bin
" folder of your JDK installation. In order to run it you must either use full path or add this directory to your systems search path via the Control Panel.
javac 位于bin
JDK 安装的“ ”文件夹中。为了运行它,您必须使用完整路径或通过控制面板将此目录添加到您的系统搜索路径。
If you installed to c:\program files\java\jdk1.6.0
your call will have to look like this:
如果您安装到c:\program files\java\jdk1.6.0
您的电话中,则必须如下所示:
c:\> "c:\program files\java\jdk1.6.0\bin\javac" -version
回答by skaffman
Umm, eclipse is an IDE, it compiles things as you go. You don't need javac.
嗯,eclipse 是一个 IDE,它会在你进行时编译。你不需要javac。
回答by Juri
If you have Eclipse installed and you can write new java apps from within it, your compilation should work already..
如果您安装了 Eclipse 并且可以在其中编写新的 Java 应用程序,那么您的编译应该已经可以工作了。
Eclipse automatically builds/compiles your system when you're saving new Java files. Just try to write a new simple Hello world app, printing something to the console (just type sysout and Ctrl+Space inside Eclipse)
当您保存新的 Java 文件时,Eclipse 会自动构建/编译您的系统。尝试编写一个新的简单 Hello world 应用程序,将一些内容打印到控制台(只需在 Eclipse 中键入 sysout 和 Ctrl+Space)
回答by Igor Zelaya
Eclipse automatically compiles all project in the workspace. YOu can disable this option if you like under Project->Build Automatically.
Eclipse 会自动编译工作区中的所有项目。如果您愿意,您可以在 Project->Build Automatically 下禁用此选项。
回答by Michael Borgwardt
You don't need a separate compiler, eclipse already compiles the application for you. What you probably want to do is to create an "executable" JAR file, which you can do in eclipse by selecting File->Export->Runnable JAR file.
您不需要单独的编译器,eclipse 已经为您编译了应用程序。您可能想要做的是创建一个“可执行”JAR 文件,您可以在 eclipse 中通过选择 File->Export->Runnable JAR 文件来完成。
Note, however, that the resulting JAR file is not a "real" (i.e. Windows binary) executable - it still needs a JRE installed on the target computer. There isn't really a way to create windows binaries; that's not how Java works. On the upside, it willwork without recompilation on a Linux or MacOS machine (if it has a JRE installed).
但是请注意,生成的 JAR 文件不是“真正的”(即 Windows 二进制)可执行文件 - 它仍然需要在目标计算机上安装 JRE。没有真正的方法来创建 Windows 二进制文件;这不是 Java 的工作方式。从正面看,它会工作,没有Linux或MacOS的机器上重新编译(如果安装了JRE)。
回答by Bernie Perez
To setup Eclipse to use the JDK you must follow these steps.
要设置 Eclipse 以使用 JDK,您必须遵循以下步骤。
1.Download the JDK
1.下载JDK
First you have to download the JDK from Suns site. (Make sure you download one of them that has the JDK)
首先,您必须从 Suns站点下载 JDK 。(确保您下载其中一个具有 JDK)
2.Install JDK
2.安装JDK
Install it and it will save some files to your hard drive. On a Windows machine this could be in c:\program files\java\jdk(version number)
安装它,它会将一些文件保存到您的硬盘驱动器。在 Windows 机器上,这可能位于 c:\program files\java\jdk(version number)
3.Eclipse Preferences
3. Eclipse 首选项
Go to the Eclipse Preferences -> Java -> Installed JREs
转到 Eclipse Preferences -> Java -> Installed JREs
4.Add the JDK
4.添加JDK
Click Add JRE and you only need to located the Home Directory. Click Browse...and go to where the JDK is installed on your system. The other fields will be populated for you after you locate the home directory.
单击添加 JRE,您只需要定位主目录。单击浏览...并转到系统上安装 JDK 的位置。找到主目录后,将为您填充其他字段。
5.You're done
5.你完成了
Click Okay. If you want that JDK to be the default then put a Check Mark next to it in the Installed JRE's list.
单击确定。如果您希望该 JDK 成为默认值,请在已安装的 JRE 列表中在它旁边放置一个复选标记。
回答by lahiru sasanka
Eclipse to use the JDKyou must follow these steps.
Eclipse 要使用JDK必须遵循这些步骤。
1.Download the JDK First you have to download the JDK from oracle site. Download link - > https://www.oracle.com/technetwork/es/java/javasebusiness/downloads/index.html
1.下载JDK 首先,您必须从oracle 站点下载JDK。下载链接-> https://www.oracle.com/technetwork/es/java/javasebusiness/downloads/index.html
2.Install JDK
2.安装JDK
Install it and it will save some files to your hard drive. On a Windows machine this could be in c:\program files\java\jdk(version number)
安装它,它会将一些文件保存到您的硬盘驱动器。在 Windows 机器上,这可能位于 c:\program files\java\jdk(version number)
3.Eclipse Preferences
3.Eclipse 偏好设置
Go to the Eclipse Preferences -> Java -> Installed JREs
转到 Eclipse Preferences -> Java -> Installed JREs
4.Add the JDK
4.添加JDK
Click Add JRE and you only need to located the Home Directory. Click Browse... and go to where the JDK is installed on your system. The other fields will be populated for you after you locate the home directory.
单击添加 JRE,您只需要定位主目录。单击浏览...并转到系统上安装 JDK 的位置。找到主目录后,将为您填充其他字段。
5.You're done
5.你完成了
Click Ok. If you want that JDK to be the default then put a Check Mark next to it in the Installed JRE's list.
单击确定。如果您希望该 JDK 成为默认值,请在已安装的 JRE 列表中在它旁边放置一个复选标记。