JRE 1.7 - java version - returns: java/lang/NoClassDefFoundError: java/lang/Object

Java

Java Problem Overview


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:

  1. The correct Java home directory, including the /bin directory, is on the global PATH

  2. JAVA_HOME is set correctly

  3. Executing the command java -fullversion works

     $ java -fullversion
    
     ./java full version "1.7.0_05-b05"
    
  4. The symbolic links in /usr/java all point to the correct java installation

  5. I did not install any 'default' java when I created the system

  6. java -version fails...same error as above

  7. Issuing the commands from under the directory structure of the java installation does not work either

  8. This is 64-bit java for a 64-bit

Any ideas?

Java Solutions


Solution 1 - Java

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 - Java

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 - Java

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.

Solution 4 - Java

Quick Solution for impatient people ;) On Windows machines, try this: Go to C:\Windows\System32 directory and delete java.exe (or rename it to something like java.exe.old).

Since at least 1.6, there should not be a java.exe in the Windows directory. If there is, it's a leftover from something.

A bit more reading:

I'm really suprised that a question from 2012 doesn't have an approved answer yet and I've actually encountered the same issue in 2015 on my Win 7 32-Bit OS!

So what did happen?

Basically, everything was working fine, I downloaded H2 database and when I tried to start H2 Console (Command Line) I got:

Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object

I found this question and I was able to confirm the same symptoms:

JAVA_HOME is set correctly:

echo %JAVA_HOME%
C:\Program Files\Java\jdk1.6.0_26

java -version fails, while java --fullversion works fine:

java -fullversion
java full version "1.6.0_45-b06"

SOLUTION: Go to C:\Windows\System32 directory and delete (I actually renamed) java.exe file!!!!

Now, I get:

java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)

and H2 Console (Command Line) works fine as well!

Credits go to the last post in this forum: https://bukkit.org/threads/java-lang-noclassdeffounderror-java-lang-object.70450/

Solution 5 - Java

I downloaded new JDK today (1.8.0.73) started c:> java.exe and got the infamous:

> Error occurred during initialization of VM > java/lang/NoClassDefFoundError: java/lang/Object

I just wanted to share my working solution on here.

When I cd'ied into the jdk\bin folder, Java would run fine so I knew it was the PATH. I set PATH to just \jdk\bin at CMD to prove it and it worked.

So, one of the folders in the PATH must have had java.exe that was causing the conflict, I thought. As it turned out, it was C:\>ProgramData\Oracle\Java\javapath that holds symlinks to the executables.

java.exe was pointing to jre\bin. The file was corrupt, when I started \jre\bin\java.exe--the exact same error. Bingo. I re-installed JRE and the problem went away. Happy coding...

Solution 6 - Java

You are most probably missing a file called rt.jar in your installation which has the class file for java.lang.Object. Check your install files etc.

In particular, note that a 64-bit intsaller overlays (or installs "next to") an existing 32-bit installation. In other words, to get a fully working 64-bit installation, you must first run the 32-bit installation, and follow that up with a 64-bit installation if you have a 64bit capable machine...

If instead you do just a 64-bit installation you will be missing certain files in the installation and will get errors such as the one above.

Solution 7 - Java

On Windows 10, I was facing the same issue with JRE 1.8 (8u121).
Typing

java -version

the cmd prompt returns

Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object

All the other commands, echo %JAVA_HOME%, echo %JRE_HOME%, echo %PATH%, java -fullversion worked fine.

Going to environment variables on system administration panel, remove from PATH the link C:\ProgramData\Oracle\Java\javapath, and be sure to have set in PATH the link to C:\Program Files\Java Folder\bin.

After that, check if in C:\Windows\System32 exists a java.exe file; if true, delete that file.

Typing now java -version it works fine.

Solution 8 - Java

This problem happens when you install the JDK by _uncompressing_ it instead of _executing_ it.

By example:

unzip jdk-6u45-linux-x64.bin  (wrong)

sh ./jdk-6u45-linux-x64.bin   (right)

In the first scenario, the runtime libraries, as rt.jar, don't get automatically uncompresessed (thus, you can find the rt.pack files, etc. instead of the .jar ones).

Solution 9 - Java

I had the same problem recently. In my case my windows 7 machine automatically downloaded java and added C:\ProgramData\Oracle\Java\javapath to the beginning of my path environment variable, which messed up my java. Once I got rid of that from the path, it worked.

Solution 10 - Java

if you do "chmod u+rx" on the java binary and run it, it will the unpack the jar files and you can do a java -version without runtime errors

Solution 11 - Java

You cannot install just the 64bit, you must first install the 32bit and then add the 64bit components.

From java.com: >Installing the JRE on a 64-bit system that allows a 32-bit JVM is a two-step process: first install the 32-bit JRE and then install the additional support for 64-bit operations. The file names are as follows:

Solution 12 - Java

If you install a 64-bit version without first installing 32-bit, this error will occur despite fixing all of the other issues. I have a brand new Dell i7 64-bit Windows 10 Pro machine running Java 8u71. After having added my %path% and %classpath% to environment variables and trying several other fixes, uninstalling 64-bit, installing 32-bit then reinstalling 64-bit fixed it.

Some of the issues, like not having your files unpacked, etc. that have been mentioned as possible causes may still be causing issues, but if you don't do this, as well, the other fixes won't work.

Solution 13 - Java

In my case, I use a windows 8.1 (installed jdk1.8.0_77), I did three things:

  1. I deleted previous jdks
  2. I renamed the java.exe file inside C:\Windows\System32
  3. I also removed C:\ProgramData\Oracle\Java\javapath in my PATH (echo %PATH%)

and voila got it fixed!

Solution 14 - Java

I have faced the similar issue and found that the symlink in program data(C:\ProgramData\Oracle\Java\javapath) was wrong. I have given the correct path and it worked.

Details on how to correct the program data is available here

Solution 15 - Java

Another answer could be to use the tar.gz file instead in the Linux case. There seem to be something like that also for the solaris platform. This way all files will already be in the expected format and there won't be any unpacking issues.

Solution 16 - Java

I have the some problem on x86_64 Linux installations with JDK 1.7.0_40 i586. I figured out that the problem is that rpm can't unpack jar files, as mentioned by Rigg802 (though rpm completes marking success):

Unpacking JAR files...
        rt.jar...
/var/tmp/rpm-tmp.zLzkkb: /usr/java/jdk1.7.0_40/bin/unpack200: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
Error: unpack could not create JAR file:

        /usr/java/jdk1.7.0_40/jre/lib/rt.jar

File /lib/ld-linux.so.2 is provided by glibc-2.12-1.107.el6_4.4.i686 which is not among rpm deps of jdk rpm.

Oracle JDK rpm also requires 32 bit versions of libgcc-4.4.7-3.el6.i686 to be installed

So, workaround is to install glibc-2.12-1.107.el6_4.4.i686 and libgcc-4.4.7-3.el6.i686 first.

Solution 17 - Java

Quick fix that worked for me:

for file in $(find "$JAVA_HOME" -name "*pack")
do 
	unpack200 "${file}" "${test_file/%pack/jar}";
done

Solution 18 - Java

I found that this error occurred when I extracted the .rpm file.

I then removed that folder and downloaded jdk-7u79-linux-x64.tar.gz for Linux 64 and extracted the contents of this file instead. Also: export JAVA_HOME=/opt/java/jdk1.7.0_79 export JDK_HOME=/opt/java/jdk1.7.0_79 export PATH=${JAVA_HOME}/bin

Solution 19 - Java

Just install the jre again. It simply solved my problem. (SonarQube startup batch started to give this error after I installed jdk)

Solution 20 - Java

Go to control panel, uninstall the java related stuff(close eclipse if opened), then re-install java and open eclipse, clean projects.

Solution 21 - Java

Just did this on Solaris and ran into this identical problem where even "java -version" does not work. There is a reason that the 64 bit versions of the distro are WAY smaller than the 32-bit. It is indeed as stated above:

In other words, to get a fully working 64-bit installation, you must first run the 32-bit installation, and follow that up with a 64-bit installation if you have a 64bit capable machine...

So I ran the installer for the 32-bit:

> sh jdk-6u131-solaris-sparc.sh

Then I ran the installer for the 64-bit:

> sh jdk-6u131-solaris-sparcv9.sh

This gives me several java executables to choose from:

  • $ find . -name java
  • ./jdk1.6.0_131/db/demo/programs/scores/java
  • ./jdk1.6.0_131/db/demo/programs/vtis/java
  • ./jdk1.6.0_131/bin/java
  • ./jdk1.6.0_131/bin/sparcv9/java
  • ./jdk1.6.0_131/jre/bin/java
  • ./jdk1.6.0_131/jre/bin/sparcv9/java

The sparcv9 java's are the 64bit versions and they work with "-version" when installed alongside the 32bit JDK.

  • ./jdk1.6.0_131/bin/sparcv9/java -version
  • java version "1.6.0_131"
  • Java(TM) SE Runtime Environment (build 1.6.0_131-b32)
  • Java HotSpot(TM) 64-Bit Server VM (build 20.131-b32, mixed mode)

-Dan

Solution 22 - Java

In window 10 there is already a path present in env as C:\>ProgramData\Oracle\Java\javapath that holds symlinks to the executables.

When I install a new version and remove that from my environment variable, my all project start showing it.

I am using eclipse oxygen in window 10

To resolve it:-

  1. I just remove path C:\>ProgramData\Oracle\Java\javapath from environment variable and added new env as JAVA_HOME and %JAVA_HOME%/bin in path

  2. I reinstall the jdk with admin privileges (delete the previous JRE folder)

  3. Open your eclipse project > right click > Goto Proprieties> In Libraries > Now remove JRE System Library > Click on Add Library > select "JRE System Library" > Click on Next > Select "Workspace default JRE(jre1.8.x_xxx)" > finish

My issue is resolved :) Hope it will help you :)

Solution 23 - Java

This fixed the problem I had on CentOS

sudo yum install java-1.8.0-openjdk-devel

also see setting JAVA_HOME & CLASSPATH in CentOS 6

Solution 24 - Java

So, I went on trying everything and at last it seems that reinstalling java after uninstalling it fixed my problem.

Solution 25 - Java

if any problem for JAVA installation version

C:\Where JAVA

will give the location of java it picking up. If you have any path other than your installation, remove those files or rename it (may be as _backup). you will get proper version of java file.

Solution 26 - Java

I had the same issue in Redhat Linux 7. This has been resolved by removing, installing the following RPMs and reload the terminal.

java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64 
java-1.8.0-openjdk-devel-1.8.0.232.b09-0.el7_7.x86_64
java-1.8.0-openjdk-headless-1.8.0.232.b09-0.el7_7.x86_64

Solution 27 - Java

I faced same issue, I have installed two java version hence it caused this issue. to confirm this go and click java icon in control panel if doesnt open then issue is same, just go and uninstall one version. piece of cake. thanks.

Solution 28 - Java

I was facing same issue: Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object

Follow below steps to resolve issue :

Step 1. Goto C:\Program Files\ and search for Java folder.

Step 2. Delete C:\Program Files\Java folder.

Step 3. Download new Jdk for your version 32 bit/64 bit from http://www.oracle.com/technetwork/java/javase/downloads/index.html

Step 4. Install JDK

Step 5: Now Set JAVA_HOME to "C:\Program Files\Java\jdk1.8.0_91"

Step 6: Open command prompt and enter java -version.

It works.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTux SkywalkerView Question on Stackoverflow
Solution 1 - JavaRigg802View Answer on Stackoverflow
Solution 2 - JavabetontalpfaView Answer on Stackoverflow
Solution 3 - JavaTommasoView Answer on Stackoverflow
Solution 4 - JavaiaforekView Answer on Stackoverflow
Solution 5 - JavaStrikerView Answer on Stackoverflow
Solution 6 - Javauser3213415View Answer on Stackoverflow
Solution 7 - JavaFrancesco MarchitelliView Answer on Stackoverflow
Solution 8 - JavakdnView Answer on Stackoverflow
Solution 9 - Javadeveloper747View Answer on Stackoverflow
Solution 10 - JavaPeter NielsenView Answer on Stackoverflow
Solution 11 - JavaAndrew SpeerView Answer on Stackoverflow
Solution 12 - JavaBryan RobinsonView Answer on Stackoverflow
Solution 13 - JavakashogiView Answer on Stackoverflow
Solution 14 - JavaSiva Kameswara Rao MunipalleView Answer on Stackoverflow
Solution 15 - JavaRythmicView Answer on Stackoverflow
Solution 16 - JavascrutariView Answer on Stackoverflow
Solution 17 - JavaLiudvikasView Answer on Stackoverflow
Solution 18 - Javauser5974531View Answer on Stackoverflow
Solution 19 - JavastratovariusView Answer on Stackoverflow
Solution 20 - JavaAteeque ShaikhView Answer on Stackoverflow
Solution 21 - Javauser7323228View Answer on Stackoverflow
Solution 22 - JavaShubham JainView Answer on Stackoverflow
Solution 23 - JavaJoe JadamecView Answer on Stackoverflow
Solution 24 - JavaPlabon DuttaView Answer on Stackoverflow
Solution 25 - JavaSumataPatilView Answer on Stackoverflow
Solution 26 - JavaRajesh P SView Answer on Stackoverflow
Solution 27 - Javasrinivasan ElangovanView Answer on Stackoverflow
Solution 28 - JavaMahesh SutarView Answer on Stackoverflow