简体   繁体   English

你如何安装JDK?

[英]How do you install JDK?

I have eclipse and I can test run java apps but I am not sure how to compile them.我有 Eclipse,我可以测试运行 Java 应用程序,但我不确定如何编译它们。 I read that I should type javac -version into my cmd.exe and see if it is recognized.我读到我应该在我的 cmd.exe 中输入 javac -version 并查看它是否被识别。 It is not.它不是。 So I went to sun's website and downloaded/installed JDK v6.所以我去了sun的网站并下载/安装了JDK v6。 Yet it still says 'javac' is an unrecognized command.然而它仍然说'javac'是一个无法识别的命令。 What am I doing wrong?我究竟做错了什么?

Thanks!谢谢!

UPDATE OK 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). UPDATE OK 在阅读了一些回复之后,我似乎想要做的是创建一个可以在另一台计算机上运行的 .jar 文件(使用运行时)。 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.这可能是因为我使用的是 Flex Builder(eclipse),但我也添加了创建 java 项目的功能。

Thanks谢谢

UPDATE OK 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 文件,我不想将其存档……制作程序的全部意义在于将其发送给用户,以便他们可以使用该程序……这就是我正在尝试的要做……为什么这么难?

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 .首先,您必须从 Suns站点下载 JDK。 (Make sure you download one of them that has the 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.单击添加 JRE,您只需要定位主目录。 Click Browse... and go to where the JDK is installed on your system.单击浏览...并转到系统上安装 JDK 的位置。 The other fields will be populated for you after you locate the home directory.找到主目录后,将为您填充其他字段。

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 列表中在它旁边放置一个复选标记。

You don't need a separate compiler, eclipse already compiles the application for you.您不需要单独的编译器,eclipse 已经为您编译了应用程序。 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.您可能想要做的是创建一个“可执行”JAR 文件,您可以在 eclipse 中通过选择 File->Export->Runnable JAR 文件来完成。

Note, however, that the resulting JAR file is not a "real" (ie Windows binary) executable - it still needs a JRE installed on the target computer.但是请注意,生成的 JAR 文件不是“真正的”(即 Windows 二进制)可执行文件 - 它仍然需要在目标计算机上安装 JRE。 There isn't really a way to create windows binaries;没有真正的方法来创建 Windows 二进制文件; that's not how Java works.这不是 Java 的工作方式。 On the upside, it will work without recompilation on a Linux or MacOS machine (if it has a JRE installed).从正面看,它工作没有Linux或MacOS的机器上重新编译(如果安装了JRE)。

javac is located in the " bin " folder of your JDK installation. javac 位于 JDK 安装的“ bin ”文件夹中。 In order to run it you must either use full path or add this directory to your systems search path via the Control Panel.为了运行它,您必须使用完整路径或通过控制面板将此目录添加到您的系统搜索路径。

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

Umm, eclipse is an IDE, it compiles things as you go.嗯,eclipse 是一个 IDE,它会在你进行时编译。 You don't need javac.你不需要javac。

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.当您保存新的 Java 文件时,Eclipse 会自动构建/编译您的系统。 Just try to write a new simple Hello world app, printing something to the console (just type sysout and Ctrl+Space inside Eclipse)尝试编写一个新的简单 Hello world 应用程序,将一些内容打印到控制台(只需在 Eclipse 中键入 sysout 和 Ctrl+Space)

Eclipse automatically compiles all project in the workspace. Eclipse 会自动编译工作区中的所有项目。 YOu can disable this option if you like under Project->Build Automatically.如果您愿意,您可以在 Project->Build Automatically 下禁用此选项。

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 程序?”

Eclipse to use the JDK you must follow these steps. Eclipse 要使用JDK必须遵循这些步骤。

1.Download the JDK First you have to download the JDK from oracle site. 1.下载JDK 首先,您必须从oracle 站点下载JDK。 Download link - > https://www.oracle.com/technetwork/es/java/javasebusiness/downloads/index.html下载链接-> 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.单击添加 JRE,您只需要定位主目录。 Click Browse... and go to where the JDK is installed on your system.单击浏览...并转到系统上安装 JDK 的位置。 The other fields will be populated for you after you locate the home directory.找到主目录后,将为您填充其他字段。

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 列表中在它旁边放置一个复选标记。

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

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