Exception in thread main java.lang.NoClassDefFoundError:

  • Context: Java 
  • Thread starter Thread starter tjaeger
  • Start date Start date
  • Tags Tags
    Thread
Click For Summary
SUMMARY

The discussion centers on resolving the "java.lang.NoClassDefFoundError" encountered while compiling Java programs in SSH Secure Shell. The error arises when the Java Virtual Machine cannot find the specified class, often due to incorrect classpath settings. Users are advised to compile Java files using 'javac [javafilename].java' and run them with 'java -classpath . [javafilename]' to ensure the current directory is included in the classpath. Proper configuration of the .bash_profile is essential, including setting the JAVADIR and CLASSPATH variables correctly.

PREREQUISITES
  • Understanding of Java programming and compilation process
  • Familiarity with SSH Secure Shell environment
  • Basic knowledge of .bash_profile configuration
  • Experience with Java classpath settings
NEXT STEPS
  • Learn about Java classpath and its significance in Java applications
  • Explore SSH Secure Shell commands for file management and execution
  • Investigate Java environment setup, including .bash_profile configurations
  • Study common Java exceptions and their troubleshooting methods
USEFUL FOR

Java developers, system administrators, and anyone troubleshooting Java compilation issues in a Secure Shell environment.

tjaeger
Messages
7
Reaction score
0
Exception in thread "main" java.lang.NoClassDefFoundError:

I was getting this error trying to compile some java programs in SSH Secure Shell. Then I made a simple "Hello World" program in my home directory to see if it would compile by typing 'java HelloWorld' but all I got was:

Caused by: java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

I looked it up on google and a website said to try compiling by typing
'java -classpath.HelloWorld' but that gave me the error:

Unrecognized option: -classpath.HelloWorld
Could not create the Java virtual machine.

I haven't used Secure Shell in a long time, any help is appreciated.
 
Technology news on Phys.org


You have to type "javac HelloWorld.java," assuming you have your .bash_profile set up correctly. Otherwise, it's trying to run a program that doesn't exist.

Also, make sure $HOME/.bash_profile has something like this in it:

JAVADIR="j2re1.6.2_xx" (note you must ensure that the proper version and release number are coded here)
export JAVADIR
PATH=/usr/java/$JAVADIR/bin:$PATH:$HOME/bin:/sbin
export PATH
CLASSPATH=/usr/java/$JAVADIR/lib:/usr/NetRexx/runlib/NetRexxR.jar
export CLASSPATH
 


Try this...

compile with this command

javac [javafilename].java

then after u get the classfile (the bytecode)

run using :

java -classpath . [javafilename]

this will specify that the classpath is the current directory ( . ----> refers current working directory).
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
5K