Setting the JVM via the command line on Windows(在 Windows 上通过命令行设置 JVM)
问题描述
是否可以指定调用java jar jar_name.jar"时使用的JVM.我的机器上安装了两个 JVM.我无法更改 JAVA_HOME,因为它可能会破坏已准备好运行的代码.
Is it possible to specify the JVM to use when you call "java jar jar_name.jar" . I have two JVM installed on my machine. I can not change JAVA_HOME as it may break code that is all ready running.
亲切的问候
斯蒂芬
推荐答案
是的 - 只需明确提供 java.exe 的路径.例如:
Yes - just explicitly provide the path to java.exe. For instance:
c:UsersJonTest>"c:Program Filesjavajdk1.6.0_03injava.exe" -version
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)
c:UsersJonTest>"c:Program Filesjavajdk1.6.0_12injava.exe" -version
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)
对正在运行的命令 shell 执行此操作的最简单方法是:
The easiest way to do this for a running command shell is something like:
set PATH=c:Program FilesJavajdk1.6.0_03in;%PATH%
例如,这是一个完整的会话,显示了我的默认 JVM,然后是路径的更改,然后是新的:
For example, here's a complete session showing my default JVM, then the change to the path, then the new one:
c:UsersJonTest>java -version
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)
c:UsersJonTest>set PATH=c:Program FilesJavajdk1.6.0_03in;%PATH%
c:UsersJonTest>java -version
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)
这不会改变显式使用 JAVA_HOME 的程序.
This won't change programs which explicitly use JAVA_HOME though.
请注意,如果您在路径中找到错误的目录 - 包括一个不存在的目录 - 您不会收到任何错误,它实际上会被忽略.
Note that if you get the wrong directory in the path - including one that doesn't exist - you won't get any errors, it will effectively just be ignored.
这篇关于在 Windows 上通过命令行设置 JVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Windows 上通过命令行设置 JVM
基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01