This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java.lang.NoClassDefFoundError" Watch "Exception in thread "main" java.lang.NoClassDefFoundError" New topic
Author

Exception in thread "main" java.lang.NoClassDefFoundError

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi,

I am trying to run a program EchoClient.java in a linux machine.It is in the path /usr/src/scripts.I have included mysqlconnector.jar also in that path and i gave the command

java -classpath mysql-connector-java-3.0.17-ga-bin.jar EchoClient1


to run the program.the following error occurs:

Exception in thread "main" java.lang.NoClassDefFoundError: EchoClient1
Caused by: java.lang.ClassNotFoundException: EchoClient1
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)



Am i wrong in setting path?please assist me to solve this error.

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  44
By using an explicit "-classpath" switch you're effectively turning off the implicit "." classpath that points to the current directory. If you add that back into it, then it should work:
java -classpath .:mysql-connector-java-3.0.17-ga-bin.jar EchoClient1


Ping & DNS - my free Android networking tools app
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

One question, The java source file name is different from the class name ?
'EchoClient.java' and you're running as 'EchoClient1'

OK

1. Go to '/usr/src/scripts'
2. java -cp "path/mysqlconnection/jar/file/directory;.; EchoClient1

I hope there is NO 'package' defined in EchoClient.java


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thank you ulf.Now it works well.

Hi Sagar Rohankar ,

The source and class name are EchoClient1.java.I have posted the wrong name by mistake.

Thank you both for your reply
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Exception in thread "main" java.lang.NoClassDefFoundError
 
Similar Threads
Problems compiling servlet
java.lang.NoClassDefFoundError
help with marcus questions
package javax.servlet.http does not exist
Exception in thread "main" java.lang.NoClassDefFoundError: Voice1