在 Windows 上通过命令行设置 JVM

Setting the JVM via the command line on Windows(在 Windows 上通过命令行设置 JVM)

本文介绍了在 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

基础教程推荐