`

unsupported major.minor version 解决方法

    博客分类:
  • Java
阅读更多

一直以来都是用jdk1.5,这次重返电信由于其系统是在jdk1.4上编译的,编译的时候出现了unsupported major.minor version49.0的错误,上网查看了一下还是一个很普遍的错误,捣鼓了两天终于捣鼓出一些东西,现分享给大家。

     何谓 major.minor,且又居身于何处呢?先感性认识并找到 major.minor 来。顺便写一段 代码,然后用 JDK 1.5 的编译器编译成class,用UltraEdit或者其他能打开非十进制文件的软件打开此class,见下图:

       




       从上图中我们看出来了什么是 major.minor version 了,它相当于一个软件的主次版本号,只是在这里是标识的一个 Java Class 的主版本号和次版本号,同时我们看到 minor_version 为 0x0000,major_version 为 0x0031,转换为十制数分别为0 和 49,即 major.minor 就是 49.0 了。

      现在不妨从 JDK 1.1 到 JDK 1.7 编译器编译出的 class 的默认 minor.major version 吧。(又走到 Sun 的网站上翻腾出我从来都没用过的古董来) 

JDK 编译器版本 target 参数 十六进制 minor.major 十进制 minor.major
jdk1.1.8 不能带 target 参数 00 03 00 2D 45.3
jdk1.2.2 不带(默认为 -target 1.1) 00 03 00 2D 45.3
jdk1.2.2 -target 1.2 00 00   00 2E 46.0
jdk1.3.1_19 不带(默认为 -target 1.1) 00 03 00 2D 45.3
jdk1.3.1_19 -target 1.3 00 00   00 2F 47.0
j2sdk1.4.2_10 不带(默认为 -target 1.2) 00 00   00 2E 46.0
j2sdk1.4.2_10 -target 1.4 00 00   00 30 48.0
jdk1.5.0_11 不带(默认为 -target 1.5) 00 00   00 31 49.0
jdk1.5.0_11 -target 1.4 -source 1.4 00 00   00 30 48.0
jdk1.6.0_01 不带(默认为 -target 1.6) 00 00   00 32 50.0
jdk1.6.0_01 -target 1.5 00 00   00 31 49.0
jdk1.6.0_01 -target 1.4 -source 1.4 00 00   00 30 48.0
jdk1.7.0 不带(默认为 -target 1.6) 00 00   00 32 50.0
jdk1.7.0 -target 1.7 00 00   00 33 51.0
jdk1.7.0 -target 1.4 -source 1.4 00 00   00 30 48.0
Apache Harmony 5.0M3 不带(默认为 -target 1.2) 00 00   00 2E 46.0
Apache Harmony 5.0M3 -target 1.4 00 00   00 30 48.0


       当然你也可以用其他方法查看版本号,比如javap -verbose XXXX(class名)。

        那么现在如果碰到这种问题该知道如何解决了吧,还会像我所见到有些兄弟那样,去找个 1.4 的 JDK 下载安装,然后用其重新编译所有的代码吗?且不说这种方法的繁琐,而且web应用程序还不一定能成功,其实大可不必如此费神,我们一定还记得 javac 还有个 -target 参数,对啦,可以继续使用 1.5 JDK,编译时带上参数 -target 1.4 -source 1.4 就 OK 啦,不过你一定要对哪些 API 是 1.5 JDK 加入进来的了如指掌,不能你的 class 文件拿到 JVM 1.4 下就会 method not found。目标 JVM 是 1.3 的话,编译选项就用 -target 1.3 -source 1.3 了。

      相应的如果使用 ant ,它的 javac 任务也可对应的选择 target 和 source

<javac target="1.4" source="1.4" ............................/>

如果是在开发中,可以肯定的是现在真正算得上是 JAVA IDE 对于工程也都有编译选项设置目标代码的。例如 Eclipse 的项目属性中的 Java Compiler 设置,如图:





       


        其实理解 major.minor 就像是我们可以这么想像,同样是微软件的程序,32 位的应用程序不能拿到 16 位系统中执行那样。

如果我们发布前了解到目标 JVM 版本,知道怎么从 java class 文件中看出 major.minor 版本来,就不用等到服务器报出异常才着手去解决,也就能预知到可能发生的问题。

其他时候遇到这个问题应具体解决,总之问题的根由是低版本的 JVM 无法加载高版本的 class 文件造成的,找到高版本的 class 文件处理一下就行了。

 

  • 大小: 68.9 KB
  • 大小: 158.4 KB
分享到:
评论
1 楼 goodguyzl 2010-07-07  
你这篇文章里提供了很多我正想要的东西,非常感谢,写得很好

相关推荐

    simian-v20

    Major version increments with each card supported. Minor version increments with each new feature. Sub-minor version increments when an existing feature changes.

    RTL88x2BUv5.6.1.6_35492.zip

    M: Major version N: miNor version P: Patch number H: Hotfix number s: SVN number y: package year m: package month d: package day COEX_VER: Coext version _beta: beta driver

    Aria2135032bit.7z

    We use 3 numbers for aria2 version: MAJOR.MINOR.PATCH. We will ship MINOR update on 15th of every month. We may skip a release if we have no changes since the last release. The feature and ...

    EurekaLog_7.5.0.0_Enterprise

    Later is supported when map2dbg.exe tool is placed in \Bin folder of EurekaLog installation (separate download is required) 5)....Added: Exception2HRESULT in EAppDLL to simplify developing DLLs with ...

    TRegware 4.02

    - Windows 2000 / XP registry is now supported. Information is stored under HKEY_CLASSES_ROOT for 2000/XP systems. - New ban-list features allows you to ban certain users from using the next version ...

    TICQClient Version

    Added ICQClientVer_Major, ICQClientVer_Minor constants in ICQWorks.pas[*] Some work-speed improvements[*] Improved info request/response procedures & events[*] Improved white pages (more compatible ...

    BURNINTEST--硬件检测工具

    Windows 98 and ME are not supported in BurnInTest version 5.3 and above. Use a version of BurnInTest prior to 5.2 for compatibility with W98 and ME. Windows 95 and Windows NT =======================...

    mesa-18.0.4

    Mesa 18.0.4 implements the OpenGL 4.5 API, but the version reported by glGetString(GL_VERSION) or glGetIntegerv(GL_MAJOR_VERSION) / glGetIntegerv(GL_MINOR_VERSION) depends on the particular driver ...

    httpd2.2.12.tar

    has passed the usual votes to release that version. Only then is the final tarball packaged, removing all -rc# designations from the version number, and tagging the tree with the release number. ...

    opensc-0.12.0.tar.gz

    NEWS for OpenSC -- History of user visible changes Complete change history is available online: ... New in 0.12.0; 2010-12-22 ...* This is an beta test version. Please be careful. Do not use in ...

    servlet2.4doc

    As of version 2.1, use encodeRedirectURL(String url) instead encodeRedirectURL(String) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to ...

    IRPTrace2.00.002.zip

    Major/Minor function Generic Parameters Information Input Output -------------------------------------------------------------------------- IRP_MJ_CREATE + + N/A IRP_MJ_CREATE_NAMED_PIPE + - - ...

    Sakemail

    Minor changes to the scanning code for the filename of attachments.1.8.2- Fixed a bug with the filename of attachments (thanks to Taufer Pavel Ing.).- Added the function IsIPAddress from hou yg (the ...

    NewSID(光学习一下代码就可以了,没看清楚介绍别运行)

    Version 1.1 corrects a relatively minor bug that affected only certain installations. It also has been updated to change SIDs associated with the permission settings of file and printer shares. ...

    RTL8188C_8192C_USB_linux_v3.4.4_4749.20121105.zip

    M: Major version N: miNor version P: Patch number s: SVN number y: package year m: package month d: package day 4. wpa_supplicant_hostapd/ 4.1 wpa_supplicant...

    曲线拟合工具CurveExpert 1.0

    now supported, similar to the implementation of QuickCalc. Changes: + If background processing is enabled, during iteration the cursor is a combined arrow/hourglass to inform the user that he/...

    Mpeg2_Decoder

    mpeg2encode / mpeg2decode ========================= MPEG-2 Encoder / Decoder, Version 1.2, July 19, 1996 &lt;br&gt; Copyright (c) 1996 MPEG Software Simulation Group &lt;br&gt; E-mail: mssg@...

    Bochs - The cross platform IA-32 (x86) emulator

    - Major configure/cpu rework allowing to enable/disable CPU options at runtime through .bochsrc (Stanislav) - Bugfixes for CPU emulation correctness and stability - Implemented X2APIC extensions ...

    eac3to V3.17

    * fixed: all non-supported MKV tracks shared the same description * fixed: incorrect framerate mismatch complaint was shown for pulldown sources * fixed: FLAC tracks in MKV files don't slow down ...

Global site tag (gtag.js) - Google Analytics