如何编译以Java 1.0为目标 [英] How to compile to target Java 1.0
问题描述
我想将代码编译为Java 1.0版.
I want to compile my code down to Java version 1.0.
我设法将其编译为1.1
:
$ java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-2~deb9u1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
$ javac -target 1.2 -source 1.2 MyClass.java
(works with some warnings)
$ javac -target 1.1 -source 1.2 MyClass.java
(works with some warnings)
但是target
选项似乎不接受1.0
:
$ javac -target 1.0 -source 1.2 MyClass.java
javac: invalid target release: 1.0
我如何定位JDK 1.0?
How do I target JDK 1.0?
我希望我的 .class 和 .jar 文件能在尽可能多的系统上运行,包括非常老的系统,包括JDK 1.0. (我无权访问运行JDK 1.0的系统.)
I want my .class and .jar file to work as many systems as possible, including very old ones, including JDK 1.0. (I don't have access to a system running JDK 1.0.)
到目前为止我已经尝试过的:
What I've tried so far:
- 使用
ecj-3.0.2.jar
编译:不支持-target 1.0
,最小值为-target 1.1
. - 使用JDK 1.0进行编译:我无法运行它,它尚未在Linux上发布.
- 使用JDK 1.1进行编译:我无法运行它,它尚未在Linux上发布.
- 使用JDK 1.2进行编译:Linux i386 javac二进制文件不起作用,这给了我分段错误.
- 使用JDK 1.3进行编译:
javac: invalid target release: 1.0
. - 使用JDK 1.4进行编译:
javac: invalid target release: 1.0
. - 使用JDK 1.5进行编译:
javac: invalid target release: 1.0
.这是第一个使用Linux amd64二进制文件的JDK. - 使用JDK 1.6进行编译:
javac: invalid target release: 1.0
. - 使用JDK 1.7进行编译:
javac: invalid target release: 1.0
. - 使用JDK 1.8进行编译:
javac: invalid target release: 1.0
. (当我问这个问题时,我首先遇到了这个错误.)
- Compiling with
ecj-3.0.2.jar
: It doesn't support-target 1.0
, the minimum is-target 1.1
. - Compiling with JDK 1.0: I couldn't run it, it wasn't released for Linux.
- Compiling with JDK 1.1: I couldn't run it, it wasn't released for Linux.
- Compiling with JDK 1.2: The Linux i386 javac binary doesn't work, it's giving me Segmentation fault.
- Compiling with JDK 1.3:
javac: invalid target release: 1.0
. - Compiling with JDK 1.4:
javac: invalid target release: 1.0
. - Compiling with JDK 1.5:
javac: invalid target release: 1.0
. This is the first JDK with Linux amd64 binaries. - Compiling with JDK 1.6:
javac: invalid target release: 1.0
. - Compiling with JDK 1.7:
javac: invalid target release: 1.0
. - Compiling with JDK 1.8:
javac: invalid target release: 1.0
. (I got this error first, when I asked the question.)
我认为-target 1.0
可以工作的原因是以下答案: https://stackoverflow.com/a/26148408
The reason why I believe that -target 1.0
may work is this answer: https://stackoverflow.com/a/26148408
推荐答案
TL; DR javac -target 1.1
(并且不使用以后添加的任何类或方法)将使其在JDK上运行> = 1.0.2(于1995-09-16发行).回溯更多的想法是不可行的,因为较早的JDK尚未公开可供试用.
TL;DR javac -target 1.1
(and not using any classes or methods that were added later) will make it work on JDK >=1.0.2 (released on 1995-09-16). It's not feasible to go back more, because earlier JDKs are not publicly available to try.
javac -target ...
标志值影响存储在.class文件中的次要版本号(字节偏移量4和5)和主版本号(字节偏移量6和7):
The javac -target ...
flag value affects the minor (byte offset 4 and and 5) and major (byte offset 6 and 7) version number stored in the .class file:
-
JDK 1.8中的
-
javac -target 1.1
生成版本45.3,由JDK 1.0.2(1995年9月16日发布),JDK 1.1.*(1997年2月发布),JDK> = 1.2(1998-2003年发布)支持12). [源]
JDK 1.0.2中的 -
javac
(来自jdk-1_0_2-win32-x86.exe
,在Linux上与wine
一起运行)生成版本45.3. - 对于k≥2,JDK版本1.k支持45.0到(44 + k).0(含)范围内的类文件格式版本. [源]
-
javac -target 1.2
生成版本46.0,受JDK> = 1.2.支持. -
javac -target 1.3
生成版本47.0,受JDK> = 1.3.支持. -
javac -target 1.4
生成版本48.0,受JDK> = 1.4的支持. - 等
javac -target 1.1
in JDK 1.8 generates version 45.3, supported by JDK 1.0.2 (released on 1995-09-16), JDK 1.1.* (released in 1997-02), JDK >=1.2 (released in 1998-12). [source]javac
in JDK 1.0.2 (fromjdk-1_0_2-win32-x86.exe
, run withwine
on Linux) generates version 45.3.- For k ≥ 2, JDK release 1.k supports class file format versions in the range 45.0 through (44+k).0 inclusive. [source]
javac -target 1.2
generates version 46.0, supported by JDK >=1.2.javac -target 1.3
generates version 47.0, supported by JDK >=1.3.javac -target 1.4
generates version 48.0, supported by JDK >=1.4.- etc.
这篇关于如何编译以Java 1.0为目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!