如何使用程序运行特定版本的 Java?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21050538/
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 to run a specific version of Java with a program?
提问by Saamoz
So I have the latest version of JRE 7 on my computer, and everything is working fine. Lately, I've downloaded a program that requires JRE 6. I know where all of the files are located on my computer, all I'm asking is the .bat file code to run a specific version of Java with only that program. I am somewhat of a newbie when it comes to Windows and Java PATH structure, so
所以我的电脑上安装了最新版本的 JRE 7,一切正常。最近,我下载了一个需要 JRE 6 的程序。我知道所有文件在我的计算机上的位置,我所要求的只是 .bat 文件代码,以便仅使用该程序运行特定版本的 Java。当谈到 Windows 和 Java PATH 结构时,我有点像新手,所以
Stanford's computer science course has you use a modified version of Eclipse to code in Java, and it was created when Java was still in version 6. If you are familiar with this, then you may know of karel the robot, a Java application that opens in Eclipse. When I tried to run this, the Karel program did not appear; only a blank screen. I found a youtube video about using Karel and many of the people in the comments had been having this problem, and some said that using JRE 6 fixed it. Also on the installation instructions, it said to use JRE 1.6, but I thought it would work with JRE 7
斯坦福的计算机科学课程有你使用修改版本的 Eclipse 用 Java 编码,它是在 Java 还在版本 6 的时候创建的。 如果你熟悉这个,那么你可能知道 karel the robot,一个打开的 Java 应用程序在 Eclipse 中。当我尝试运行它时,没有出现 Karel 程序;只有一个空白屏幕。我发现了一个关于使用 Karel 的 YouTube 视频,评论中的许多人都遇到了这个问题,有些人说使用 JRE 6 修复了它。同样在安装说明中,它说使用 JRE 1.6,但我认为它可以与 JRE 7 一起使用
回答by Tantowi Mustofa
you can call each java.exe directly.
您可以直接调用每个 java.exe。
You can create 2 batch file named java6.bat and java7.bat :
您可以创建 2 个名为 java6.bat 和 java7.bat 的批处理文件:
java6.bat
java6.bat
@echo off
"C:\Program Files\Java\jre6\bin\java.exe" %*
java7.bat
java7.bat
@echo off
"C:\Program Files\Java\jre7\bin\java.exe" %*
to call a program with jre6
用 jre6 调用程序
java6 -jar helloworld.jar
and to call a program with jre7
并使用 jre7 调用程序
java7 -jar helloworld.jar
回答by A4L
If you mean this programthen I had no problem launching it with java 7
如果你的意思是这个程序,那么我用 java 7 启动它没有问题
However if you really need java 6 for operating it then you could write some .bat
file like this:
但是,如果您确实需要 java 6 来操作它,那么您可以编写如下.bat
文件:
@echo off
set JAVA_HOME=C:\oracle\jdk1.6
set MY_CLASSPATH=lib\karelj.jar;lib\silk.jar
%JAVA_HOME%\bin\javaw.exe -cp %MY_CLASSPATH% karel.swingui.Main