标题翻译
How to run .jar file using a specific JRE version from a .bat file?
问题
以下是翻译好的部分:
所以我正在尝试运行一个需要 Java 7 的 JAR 文件。我安装了 Java 7 JRE,但当我使用 java -jar...
命令时,它仍在使用 Java 8。
这是我在要运行的 .bat
文件中的内容,而 mcpc-plus-1.4.7.jar
就在与批处理文件相同的文件夹中。
"C:\Program Files\Java\jre7\bin\java.exe" -jar mcpc-plus-1.4.7.jar -Xms1G -Xmx2G -XX:MaxPermSize=256M nogui -nojline
需要注意的一点是,当我打开命令提示符并运行 java -jar ...
命令时,它按预期工作,但它会下载并在 JRE 位置创建所有内容,这不是我想要的。
这是在评论中运行建议命令后得到的结果。
环境变量 JAVA_HOME 未定义
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Windows\System32\OpenSSH\;
C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
D:\Programs\brackets\command;
C:\Users\...\AppData\Local\Microsoft\WindowsApps;
C:\Users\...\AppData\Local\GitHubDesktop\bin;
D:\Programs\Nmap)
英文翻译
So I'm trying to run a jar file which requires Java 7. I installed java 7 JRE but when i use java -jar...
its still using java 8.
This is what I have in the .bat
file I'm trying to run and mcpc-plus-1.4.7.jar
is in the same folder as the [tag:batch-file].
"C:\Program Files\Java\jre7\bin\java.exe" -jar mcpc-plus-1.4.7.jar -Xms1G -Xmx2G -XX:MaxPermSize=256M nogui -nojline
One thing to note when I open the Command Prompt and run java -jar ...
it works as it should, but it downloads and creates everything in the JRE location, which is not what I want.
This is what I get after running the suggested commands within the comments.
Environment variable JAVA_HOME, not defined
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Windows\System32\OpenSSH\;
C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
D:\Programs\brackets\command;
C:\Users\...\AppData\Local\Microsoft\WindowsApps;
C:\Users\...\AppData\Local\GitHubDesktop\bin;
D:\Programs\Nmap)
答案1
得分: 0
这是一种常见的做法,将JAVA_HOME设置为所需使用的JDK或JRE的路径,然后使用所需的参数执行%JAVA_HOME%\bin\java.exe。
这样可以通过设置一个简单的变量来选择Java版本。
英文翻译
It is a common practice to set HAVA_HOME to point to the JDK or JRE you want to use, then execute %JAVA_HOME%\bin\java.exe with the necessary parameters.
This allows you to choose the Java version by setting one simple variable.
专注分享java语言的经验与见解,让所有开发者获益!
评论