天天看點

處理報錯:java/lang/NoClassDefFoundError: java/lang/Object

處理報錯:java/lang/NoClassDefFoundError: java/lang/Object

作業系統環境:CentOS6.0 2.6.32-220.el6.x86_64

JDK版本環境:jdk1.5.0_22

作業系統原來安裝的是jdk1.6,後來開發人員要求java程式使用jdk1.5版本的。幫開發下載下傳JDK1.5,

安裝完JDK ,設定環境變量後出現這個錯誤:

[root@fztest97 lib]# javac

Error occurred during initialization of VM

java/lang/NoClassDefFoundError: java/lang/Object

[root@fztest97 lib]# java

首先要确認的是環境變量的設定是否正确,其次,需要确認的就是lib和jre/lib檔案夾中的rt和tools是否是打包後的形式,如果發現rt.pack 和 tools.pack 那麼多半問題就出在這裡。

解決方法也很簡單,隻要将相應檔案解壓成rt.jar 和 tools.jar,可以使用bin裡面的unpack200工具,

如:unpack200 rt.pack rt.jar

/apps/usr/java/jdk1.5.0_22/lib/tools.pack 轉為 tools.jar 

/apps/usr/java/jdk1.5.0_22/jre/lib/rt.pack 轉為 rt.jar

執行如下操作指令:

[root@fztest97 ]# cd /apps/usr/java/jdk1.5.0_22/lib/

[root@fztest97 lib]# unpack200 tools.pack tools.jar

[root@fztest97 lib]# ls

dt.jar ir.idl jconsole.jar orb.idl sa-jdi.jar tools.jar tools.pack

[root@fztest97 lib]# cd /apps/usr/java/jdk1.5.0_22/jre/lib

[root@fztest97 lib]# unpack200 rt.pack rt.jar

[root@fztest97 lib]# ll rt.*

-rw-r--r--. 1 root root 40232487 May 23 19:23 rt.jar

-rw-r--r--. 1 root root 12960918 May 23 19:07 rt.pack

再次執行如下指令,進行驗證:

[root@fztest97 lib]# java -version

java version "1.5.0_22"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)

Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_22-b03, mixed mode)

Usage: javac <options> <source files>

where possible options include:

-g Generate all debugging info

-g:none Generate no debugging info

-g:{lines,vars,source} Generate only some debugging info

-nowarn Generate no warnings

-verbose Output messages about what the compiler is doing

-deprecation Output source locations where deprecated APIs are used

-classpath <path> Specify where to find user class files

-cp <path> Specify where to find user class files

-sourcepath <path> Specify where to find input source files

-bootclasspath <path> Override location of bootstrap class files

-extdirs <dirs> Override location of installed extensions

-endorseddirs <dirs> Override location of endorsed standards path

-d <directory> Specify where to place generated class files

-encoding <encoding> Specify character encoding used by source files

-source <release> Provide source compatibility with specified release

-target <release> Generate class files for specific VM version

-version Version information

-help Print a synopsis of standard options

-X Print a synopsis of nonstandard options

-J<flag> Pass <flag> directly to the runtime system

到此為止,JDK1.5安裝配置成功。

     本文轉自vcdog 51CTO部落格,原文連結:http://blog.51cto.com/255361/874171,如需轉載請自行聯系原作者