1

I am using Linux Ubuntu 13.10 I am trying to run a script and get the following error:

/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar: Success

Error occurred during initialization of VM

java/lang/NoClassDefFoundError: java/lang/Object

I have:

javac -version

javac 1.7.0_51

java -version

java version "1.7.0_51"

OpenJDK Runtime Environment (IcedTea 2.4.4) (7u51-2.4.4-0ubuntu0.13.10.1)

OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

When I run: echo $CLASSPATH: I get blank output

echo $JAVA_HOME: blank output

Please help me, how to resolve this.

Death Metal
  • 830
  • 3
  • 9
  • 26
  • set your JAVA_HOME to the JDK directory – Sanjeev Feb 27 '14 at 08:53
  • how do I that? I do not know . :( – Death Metal Feb 27 '14 at 08:54
  • on commandprompt execute "export JAVA_HOME=" without the quotes – Sanjeev Feb 27 '14 at 08:57
  • Done export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 Still getting the same error. – Death Metal Feb 27 '14 at 09:00
  • try putting this command for setting JAVA_HOME in your script itself. as your script might be running in a new shell – Sanjeev Feb 27 '14 at 09:09
  • Have a look and see if GNU CLASSPATH is installed, and delete it if present. It is useful to neither man nor beast. – user207421 Feb 27 '14 at 09:21
  • This is answered at [A previous question](https://stackoverflow.com/questions/11808829/jre-1-7-returns-java-lang-noclassdeffounderror-java-lang-object/30577609), which tells you how to resolve this. – Chris Aug 16 '18 at 15:27
  • This is answered at [A previous question](https://stackoverflow.com/questions/11808829/jre-1-7-returns-java-lang-noclassdeffounderror-java-lang-object/30577609), which tells you how to resolve this. – Chris Aug 16 '18 at 15:28

2 Answers2

2

You have to set your CLASSPATH and JAVA_HOME environment variables. Take a look at this:

https://askubuntu.com/questions/186693/how-set-classpath-variable-for-a-folder-in-ubuntu http://www.wikihow.com/Set-Up-Your-Java_Home-Path-in-Ubuntu

This could be useful as example, replacing the directories by yours:

export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/bin"

export CLASSPATH=".:/usr/lib/jvm/java-7-openjdk-i386/lib"

Community
  • 1
  • 1
Andres
  • 10,561
  • 4
  • 45
  • 63
  • 6
    You haven't had to set the CLASSPATH since about 1998, and setting the classpath to a directory has zero effect unless the directory is the root of a package-structured hierarchy of .class files, which `lib` is not. – user207421 Feb 27 '14 at 09:04
  • @Andres: Thank you for your help. I did both the commands, but still getting the error. I removed the "". – Death Metal Feb 27 '14 at 09:05
  • Are you sure you're pointing to the correct directories? Also, dont remove the ".". That will allow the JVM to find classes starting from the current directory. – Andres Feb 27 '14 at 09:05
1

After you compile your code, you end up with .class files for each class in your program. These binary files are the bytecode that Java interprets to execute your program. The NoClassDefFoundError indicates that the classloader, which is responsible for dynamically loading classes, cannot find the .class file for the class that you're trying to use. It probably indicates that you haven't set the classpath option when executing your code. This link explains how to set the classpath when you execute

Maulik Patel
  • 2,742
  • 4
  • 19
  • 28