1. Sep 3, 2008

tjaeger

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)

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.

2. Sep 5, 2008

OrbitalPower

Re: Exception in thread "main" java.lang.NoClassDefFoundError:

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
export CLASSPATH

3. Sep 22, 2008

dildog

Re: Exception in thread "main" java.lang.NoClassDefFoundError:

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