• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception in thread "main" java.lang.NoClassDefFoundError

 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic