如何仅使用 JRE 在没有 JDK 的情况下编译和运行 Java 程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31493980/
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 can I able to compile and run java programs without JDK with just JRE?
提问by Saran
I have installed JRE in my machine and downloaded Eclipse IDE and started to work on that IDE.
我已经在我的机器上安装了 JRE 并下载了 Eclipse IDE 并开始在该 IDE 上工作。
I have read from some blogs like Without JDK we can't compile the java program but i can able to run program/application in eclipse IDE.
我读过一些博客,比如没有 JDK,我们无法编译 java 程序,但我可以在 Eclipse IDE 中运行程序/应用程序。
Then in some other blogs gave me information like eclipse will have own JDK so try to run in command prompt to get know information. When i try to compile the program in bin folder(C:\Program Files\Java\jre7\bin) via command prompt it says javac couldn't recognize. I thought it's because of compiled class file is missing as JDK is not installed so i have copied the project from Eclipse IDE with class file and try to run the program it says couldn't find or load main class filename.java.
然后在其他一些博客中给了我信息,例如 eclipse 将拥有自己的 JDK,因此尝试在命令提示符下运行以获取相关信息。当我尝试通过命令提示符编译 bin 文件夹(C:\Program Files\Java\jre7\bin)中的程序时,它说 javac 无法识别。我认为这是因为未安装 JDK 导致缺少已编译的类文件,所以我从 Eclipse IDE 中复制了带有类文件的项目,并尝试运行它说找不到或加载主类 filename.java 的程序。
Even i have set environment variable as Java_home for the JRE bin path.
即使我已将环境变量设置为 JRE bin 路径的 Java_home。
Pls explain JDK and JRE difference in brief to me.
请向我简要解释 JDK 和 JRE 的区别。
回答by Ankit Nigam
Not possible to compile your java code in absence of JDK. javac
, the java compiler, and other Java Development related binaries are available in the JDK only not in JRE.
在没有 JDK 的情况下无法编译您的 Java 代码。javac
、java 编译器和其他与 Java 开发相关的二进制文件在 JDK 中可用,但在 JRE 中不可用。
For Getting Differences between JRE and JDK , you can refer here.
有关 JRE 和 JDK 之间的差异,您可以参考此处。
回答by Saran
I understood the concept now.
我现在明白了这个概念。
Application is running in eclipse even without JDK installation as eclipse has its own compiler and JRE installed in my machine.
即使没有安装 JDK,应用程序也在 eclipse 中运行,因为 eclipse 有自己的编译器和 JRE 安装在我的机器上。
Copy of project from Eclipse IDE with class file is throwing error like 'couldn't find or load main class filename.java' because runtime environment couldn't find the class file as Javac compiler and Eclipse compiler class will be different so content will be different. So java interpreter couldn't find the class file of eclipse compiler class file(As similar to serialization concept).
带有类文件的 Eclipse IDE 项目副本抛出错误,如“无法找到或加载主类文件名.java”,因为运行时环境找不到类文件,因为 Javac 编译器和 Eclipse 编译器类将不同,因此内容将是不同的。所以java解释器找不到eclipse编译器类文件的类文件(类似于序列化概念)。
回答by coder97
The JDK, or Java Development Kit, allows commands such as `java` and `javac`. The JDK is required to develop and run Java applets and applications.
JDK 或 Java 开发工具包允许诸如 `java` 和 `javac` 之类的命令。开发和运行 Java 小程序和应用程序需要 JDK。
The JRE is used to run Java programs. It is required to run any Java programs.
JRE 用于运行 Java 程序。运行任何 Java 程序都需要它。
This might help: https://stackoverflow.com/a/29160633/6423975
这可能会有所帮助:https: //stackoverflow.com/a/29160633/6423975