140

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?

Ravi Parekh
  • 5,253
  • 9
  • 46
  • 58
Tux Skywalker
  • 1,405
  • 2
  • 10
  • 6

28 Answers28

190

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.

MultiplyByZer0
  • 6,302
  • 3
  • 32
  • 48
Rigg802
  • 2,666
  • 1
  • 16
  • 14
  • 2
    This is a Solaris question, not Windows. – Robin Kanters May 03 '13 at 21:57
  • 1
    This solution helped if you just download java linux archive file, and don't want use installation scripts. – PotOfTea Jul 30 '13 at 14:10
  • 23
    @Robin Kanters as this exact problem/error message, its symptoms and ways of fixing it are platform-agnostic, *This is a Java RE question, not Solaris.* –  Mar 06 '14 at 18:47
  • 1
    confirm having this problem on windows after java did some auto update – Lassi Kinnunen Nov 14 '14 at 03:46
  • I installed a jdk on Ubuntu with alien + dpkg, and I still had this problem. Fortunately, this worked. – Charles Wood Jan 13 '15 at 18:41
  • 5
    I always just use `for %i in (*.pack) do (..\bin\unpack200 "%i" "%~ni.jar" & del "%i")` (Maybe some day I’ll make it a bit more robust so that I don’t have to manually change the path, but then again, I usually just use the `.gz` release of the JRE which doesn’t pack them.) – Synetech Dec 11 '15 at 18:23
  • @Synetech Thanks, this helped me to install the exe manually (without executing it) DON'T FORGET jre/lib/ext ! – pdem Jan 07 '16 at 08:14
  • I got another issue: Error: Could not find or load main class com.sun.tools.javac.Main. What worked for me was going again to lib subfolder. And execute `..\bin\unpack200 -r -v -l "" tools.pack tools.jar`. Now `javac -version` also works. – Melroy van den Berg Jan 12 '16 at 11:32
  • +1. Had this from some kind of unknown, silent installation error when upgrading from Fedora 28 to Fedora 30. Even a `dnf reinstall` of the relevant openjdk RPMs didn't fix it. The java root at /usr/java/jdk1.8.0_71/jre/ still had all of its .pack files unpacked. The `find` script worked like a charm. Thank you! – Eric L. Jun 10 '19 at 17:18
31

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.

MultiplyByZer0
  • 6,302
  • 3
  • 32
  • 48
betontalpfa
  • 3,454
  • 1
  • 33
  • 65
  • 3
    To developing you have to unpack some other packages: in `"/lib"` `../bin/unpack200 tools.pack tools.jar` in `"/jre/lib/ext"` `../../bin/unpack200 jfxrt.pack jfxrt.jar` `../../bin/unpack200 localedata.pack localedata.jar` – betontalpfa Jun 16 '14 at 14:43
  • Some scripts can be found here to unpack all missing jars from a manually extracted JDK: http://stackoverflow.com/questions/2203922/how-to-extract-only-the-contents-of-the-jdk-installer – Kloe2378231 Jan 14 '15 at 12:09
  • 1
    This was the problem in my case. I am using Ubuntu 18.04. Thank you! – Boncho Valkov Jul 30 '19 at 14:46
13

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.

Tommaso
  • 131
  • 1
  • 4
  • 3
    Where did you get that `architecture independent files as rt.jar are distributed only in the 32-bin version`? – Aleksandr M Oct 10 '12 at 08:39
  • I just examined the contents of the distribution – Tommaso Oct 10 '12 at 09:42
  • +1 Yep, you are correct. rt.jar is not included in jre package for solaris 64-bit. – Aleksandr M Oct 10 '12 at 10:18
  • 3
    To add to this - we ran across this when doing a manual install on SmartOS. Follow the instructions found at https://blogs.oracle.com/thefield/entry/solaris_11_jdk_installation (for the most part) and you'll be ok. – Khushil Mar 08 '13 at 15:38
  • I installed both packages jdk-7u79-solaris-sparcv9.tar.Z and jdk-7u79-solaris-sparc.tar.Z. Now it looks like it is working. Ty. – Alex Pi Apr 01 '16 at 16:18
  • that link doesn't work anymore but I downloaded both installs and copied the 64-bit one over top of the 32-bit one, and that did the trick – Jeramy Rutley Sep 11 '19 at 00:18
12

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/

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
iaforek
  • 2,860
  • 5
  • 40
  • 56
  • I too am facing this problem, but it looks like in your case you are simply using an older version of java. 1.6.0_26 != 1.6.0_45, your older version probably just doesn't have the issue. – Centimane Jun 03 '15 at 12:47
  • Well spotted! I have JDK 1.6.0_26 installed and that "newer" version came from Windows System32 folder. Both are in PATH environment variable and I actually don't want to use Windows supplied java runtime. Therefore, deleting it solved the issue. Maybe you have two java runtimes in your PATH too? – iaforek Jun 03 '15 at 14:23
  • For me my install was missing rt.jar (which is where you find java.lang.Object). Unfortunately when I install the RPM from kickstart it's missing the rt.jar, but if I install after it's there, a funny problem to have. – Centimane Jun 03 '15 at 14:28
  • I can't help you with RPMs. Sorry about that. – iaforek Jun 03 '15 at 14:35
  • 4
    For me the symbolic links for java in `C:\ProgramData\Oracle\Java\javapath` were causing the problem. I change the PATH environment variable and now it works. – WhiteKnight Jan 22 '16 at 10:31
  • This fixed my issue straight away. Thanks. – Warren Reilly Feb 08 '16 at 10:45
  • While I do not question the value of this answer in a *greater* context it just doesn't apply to the problem at hand. The OP is clearly **not** on a Windows platform. But then again, most other answers to this question have fallen into this trap. :-) – peterh Dec 22 '16 at 09:09
11

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

Will
  • 24,082
  • 14
  • 97
  • 108
Striker
  • 331
  • 3
  • 6
8

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.

user3213415
  • 81
  • 1
  • 1
  • It's part of the answer. You need to unpack all the *.pack files within your /lib and lib/ext directory of your java SDK path. unpack200 can help you with this. Please, see the comment of Rigg802. – Melroy van den Berg Jan 12 '16 at 11:36
7

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).

Muhammad Usman
  • 1,366
  • 5
  • 18
  • 33
kdn
  • 71
  • 1
  • 1
7

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.

Brethlosze
  • 1,533
  • 1
  • 22
  • 41
  • 2
    I have the same problem after windows update however I do not have folder `C:\Program Files\Java Folder\bin`. Instead I use `C:\Program Files\Java\jdk1.8.0_161\bin` but it does not help me anyway. There is no file java.exe in folder System32 – Tom Jun 05 '18 at 12:47
5

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.

developer747
  • 15,419
  • 26
  • 93
  • 147
4

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

4

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:

2

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.

2

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!

kashogi
  • 21
  • 2
2

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

Community
  • 1
  • 1
1

Quick fix that worked for me:

for file in $(find "$JAVA_HOME" -name "*pack")
do 
    unpack200 "${file}" "${test_file/%pack/jar}";
done
Liudvikas
  • 396
  • 3
  • 4
1

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

1

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

stratovarius
  • 3,720
  • 1
  • 30
  • 26
1

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

Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
1

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

  • True, but the question is from 2012 and we do not know the OP's platform. He's referring to `/usr/java` so it is clearly a Linux/Unix like OS. You are right that the Solaris install of Java was different from any other OS up until Java8. You basically had to install first the 32bit package and then the 64bit package *on top* of it. But that's all in the past now that 32-bit Java is no longer supported on Solaris, similar to say Mac OS X. – peterh Dec 22 '16 at 08:58
0

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.

Rythmic
  • 759
  • 2
  • 10
  • 25
  • What do you mean use the tar.gz file instead? – Koray Tugay Apr 21 '16 at 19:08
  • Considering I answered this about 2.5 years ago I had to take a look back at the java download site. There you have a choice to download java either as packaged like .rpm for LinuX. I think I tried it before and ran into trouble. Downloading the tar.gz file instead worked better as it had all the content in it in the desired file format. – Rythmic Apr 22 '16 at 20:50
0

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.

scrutari
  • 1,378
  • 2
  • 17
  • 33
  • I've the same issue with Fedora 20 and install libgcc-4.8.2-7.fc20.i686 it solve the issue. Txs – Pipe May 05 '14 at 10:41
0

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.

0

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 :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0

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

Joe Jadamec
  • 156
  • 1
  • 8
0

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

Plabon Dutta
  • 6,819
  • 3
  • 29
  • 33
0

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.

0

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

Rajesh P S
  • 21
  • 1
  • 5
-2

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.