JRE 1.7 - java version - returns: java/lang/NoClassDefFoundError: java/lang/Object
When running any java application, or just 'java', the jvm fails:
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
Here is a list of wrong answers:
The correct Java home directory, including the /bin directory, is on the global PATH
JAVA_HOME is set correctly
-
Executing the command java -fullversion works
$ java -fullversion ./java full version "1.7.0_05-b05"
The symbolic links in /usr/java all point to the correct java installation
I did not install any 'default' java when I created the system
java -version
fails...same error as aboveIssuing the commands from under the directory structure of the java installation does not work either
This is 64-bit java for a 64-bit
Any ideas?
Solution 1:
This problem stems from an improper Java installation.
Possibility 1
NOTE: This scenario only applies to Java 8 and prior. Beginning with Java 9, the JRE is structured differently. rt.jar and friends no longer exist, and Pack200 is no longer used.
The Java standard library is contained in various JARs, such as rt.jar
, deploy.jar
, jsse.jar
, etc. When the JRE is packaged, these critical JAR files are compressed with Pack200 and stored as rt.pack
, deploy.pack
, jsse.pack
, etc. The Java installer is supposed to uncompress them. If you are experiencing this error, apparently that didn't happen.
You need to manually run unpack200
on all .pack
files in the JRE's lib/
and lib/ext/
folders.
Windows
To unpack one .pack
file (for example rt.pack
), run:
"%JAVA_HOME%\bin\unpack200" -r -v rt.pack rt.jar
To recursively unpack all .pack
files, from the JRE root run:
for /r %f in (*.pack) do "%JAVA_HOME%\bin\unpack200.exe" -r -q "%f" "%~pf%~nf.jar"
*nix
To unpack one .pack
file (for example rt.pack
), run:
/usr/bin/unpack200 -r -v rt.pack rt.jar
To recursively unpack all .pack
files, from the JRE root run:
find -iname "*.pack" -exec sh -c "/usr/bin/unpack200 -r -q {} \$(echo {} | sed 's/\(.*\.\)pack/\1jar/')" \;
Possibility 2
You misinstalled Java in some other way. Perhaps you installed without admin rights, or tried to simply extract files out of the installer. Try again with the installer and/or more privileges. Or, if you don't want to use the installer, use the .tar.gz
Java package instead.
Solution 2:
For Java 8 on a *nix OS, go to <jdk root>/jre/lib
(for me, /usr/java/jdk1.8.0_05/jre/lib
). From this directory, execute:
../../bin/unpack200 rt.pack rt.jar
../../bin/unpack200 jsse.pack jsse.rar
../../bin/unpack200 charsets.pack charsets.jar
To prevent version problems in case you have another JRE installed, use the same unpack200
that ships with the JRE you are fixing – that is, from the command line, use ../../bin/unpack200
(for me, this expands to /usr/java/jdk1.8.0_05/bin/unpack200
), not just unpack200
.
Solution 3:
It seems that for a 64 bit architecture you have to install both the 32-bit version and the 64-bit version of jre (architecture independent files as rt.jar are distributed only in the 32-bit version).
Remember then to pay attention to include the correct java executable on the global PATH environment variable.