强制 Java 最低版本与“java -version:<value>"一起运行不适用于 Windows [英] Enforcing Java minimum version to run with &quot;java -version:&lt;value&gt;&quot; doesn&#39;t work on Windows

查看:28
本文介绍了强制 Java 最低版本与“java -version:<value>"一起运行不适用于 Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的应用程序应运行的最低 JVM 版本强制为 1.6 或更高(即 1.6+).我的理解是,您可以使用-version:"命令行参数来执行此操作.我试了一下,在Linux下好像可以,但在Windows下不行.

I want to enforce the minimum version of JVM my application should run on to 1.6 or greater (i.e. 1.6+). My understanding is that you can do this using the "-version:" command line argument. I tried it, and it seemed to work fine under Linux but not under Windows.

Linux

我在 Linux 机器上安装了 JDK 版本 1.6.0_21.$JAVA_HOME 和 $PATH 环境变量已设置为应有的值.

I have a JDK version 1.6.0_21 installed on a Linux machine. The $JAVA_HOME and $PATH environment variables have been set to what they should be.

我运行了以下内容:

$ java -version:1.6+ -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b16, mixed mode)

$ java -version:1.5+ -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b16, mixed mode)

$ java -version:1.7+ -version
Unable to locate JRE meeting specification "1.7+"

一切似乎都在意料之中.version:1.6+"和version:1.5+"应该可以工作,因为我安装了 JDK 1.6.0_21,而version:1.7+"应该可以,因为我没有安装 JDK 1.7.

All seemed to be expected. "version:1.6+" and "version:1.5+" should work because I have a JDK 1.6.0_21 installed, and "version:1.7+" shouldn't because I don't have a JDK 1.7 installed.

WINDOWS

我在 Windows 机器上安装了相同的 JDK 版本 1.6.0_21(更具体地说是 Windows 7).%JAVA_HOME% 和 %PATH% 环境变量已设置为应有的值.

I have the same JDK version 1.6.0_21 installed on a Windows machine (Windows 7 to be more specific). The %JAVA_HOME% and %PATH% environment variables have been set to what they should be.

我运行了以下内容:

$ java -version:1.6+ -version
Unable to locate JRE meeting specification "1.6+"

$ java -version:1.5+ -version
Unable to locate JRE meeting specification "1.5+"

$ java -version:1.7+ -version
Unable to locate JRE meeting specification "1.7+"

每次执行都会出错.

  • 谁能解释为什么相同的命令行参数在 Linux 上有效,而在 Windows 上无效?这是功能还是错误?

  • Can anyone explain why does the same command line argument work on Linux, but not on Windows? Is this a feature or a bug?

我可以做些什么来修复/解决它?我希望尽可能在 Linux 和 Windows 上应用相同的命令行参数,因此我不必为 Linux 指定不同的-version:"参数,为 Windows 指定另一个不同的参数.

What can I do to fix/work around it? As much as possible I want to have the same command line arguments applied on both Linux and Windows, so I don't have to specify a different "-version:" argument for Linux and another different one for Windows.

谢谢.

推荐答案

  • 谁能解释为什么相同的命令行参数在 Linux 上有效,而在 Windows 上无效?这是功能还是错误?

我认为这与 Linux 与 Windows 无关,而是特定发行版的问题 - 我现在可以使用 Oracle JDK 在 Windows 上很好地运行它,即 Sun JDK 的后续版本(通过 PowerShell 或CMD):

I don't think it is related to Linux vs. Windows, rather an issue with particular distributions - I can run this just fine on Windows with the Oracle JDK now, i.e. the successor of the Sun JDK (both via PowerShell or CMD):

PS> java -version:1.7+ -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

相反,我在使用 OpenJDK 的 Ubuntu 12.04 LTS 上失败了:

On the contrary, it fails for me on Ubuntu 12.04 LTS with OpenJDK:

$ java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (IcedTea 2.4.4) (7u51-2.4.4-0ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
$ java -version:1.7+ -version
Error: Unable to locate JRE meeting specification "1.7+"

简短的搜索揭示了以下有些不确定的问题:

A short search reveals the following somewhat inconclusive issues:

  • java -version:release 选项无法按照文档工作 (JDK-8011079)
    • java -version:release option does not work as documented (JDK-8011079)
      • The referenced link is broken, the current one is https://blogs.oracle.com/ksrini/entry/java_launcher_tricks_with_multiple; regardless, I currently fail to see how the referenced docs address the issue though.

      我已经确认在 Ubuntu 13.10 和 Amazon Linux 2013.09.2 上使用 OpenJDK 6/7 仍然会破坏这个问题,所以我建议尝试不同的 OpenJDK 发行版或 JDK 供应商,以防这个问题很普遍——这绝对是一个奇怪的问题,尤其是.同时,给定的 OpenJDK 是官方 Java SE 7 参考实现.

      I've confirmed this to still be broken with OpenJDK 6/7 on Ubuntu 13.10 and also on Amazon Linux 2013.09.2, so I suggest to experiment with a different OpenJDK distribution or JDK vendor, in case this issue is prevalent - it's definitely an odd issue, esp. given OpenJDK is meanwhile the official Java SE 7 Reference Implementation.

      这篇关于强制 Java 最低版本与“java -version:<value>"一起运行不适用于 Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆