针对不同版本的 JRE [英] Target different version of JRE

查看:32
本文介绍了针对不同版本的 JRE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Windows Surface Pro 上测试 Java.Surface Pro 具有 Java 7 Update 55,但没有安装 JDK.

I'm testing Java on a Windows Surface Pro. The Surface Pro has Java 7 Update 55, but does not have the JDK installed.

我使用 javac 从命令行在我的 MacBook 上编译了一个程序.MacBook 具有 Java 8 Update 5,并且包含 JDK(显然是因为我是在 MBP 上编译的).

I compiled a program on my MacBook from the command line using javac. The MacBook Has Java 8 Update 5 and it includes the JDK (obviously because I compiled on the MBP).

当我将程序从 MackBook 移动到 Surface Pro 时,出现以下错误.这里的移动程序"是指将两个*.class文件复制到新机器上,并尝试执行字节码.

When I move the program from the MackBook to the Surface Pro, I get the following error. Here, "moving the program" means copying the two *.class files to the new machine and trying to execute the byte codes.

java.lang.UnsupportedClassVersionError: HttpsTest : Unsupported major.minor version 52.

尝试使用目标信息进行编译会导致:

Trying to compile with target information results in:

$ javac -target 1.7 HttpsTest.java SSLSocketFactoryEx.java
javac: target release 1.7 conflicts with default source release 1.8

javac -help 没有列出任何控制编译程序版本信息的选项(除了 target,它似乎不起作用).

javac -help does not list any options to control the version information of the compiled program (other than target, which does not appear to work).

如何为 JRE 的下层版本编译源文件?在本例中,我的目标是来自 Java 8 机器的 Java 7.

How do I compile my source files for down level versions of a JRE? In this case, I'm targeting Java 7 from a Java 8 machine.

推荐答案

从命令行,将您的调用更改为:

From the command line, change your call to:

javac -source 1.7 -target 1.7 HttpsTest.java SSLSocketFactoryEx.java

javac(用于 JDK 8)的文档是 这里.

The documentation for javac (for JDK 8) is here.

javac(用于 JDK 9)的文档是 此处.

The documentation for javac (for JDK 9) is here.

注意:在 JDK 9 中,-target 被替换为 --release.

Note: In JDK 9, -target is replaced with --release.

这篇关于针对不同版本的 JRE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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