• 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

java programs not running due to seting classpath

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i wanted to practice developing database programs in java so i set the classpath to E:\software\installed\java\jre\lib by declaring a new environmental variable classpath and gave value as E:\software\installed\java\jre\lib but now i am unable to run any program(not even non-database) i get an error

Error: Could not find or load main class MysqlConnect

but when i delete the classpath variable i am able to run non-database programs. what is the possible problem and please let me know the solution. i have set path to E:\software\installed\java\bin

nothing is helping i tried using class path switch in java which is not helping (java -cp C:\Program Files\MySQL\MySQL Server 5.5 MysqlConnect) nor do setting path is helping (set CLASSPATH=%CLASSPATH%:C:\Program Files\MySQL\MySQL Server 5.5:C:\Program Files\MySQL\MySQL Server 5.5\mysql-connector-java-5.1.20-bin.jar) all are giving the error

Error: Could not find or load main class MysqlConnect

also whenever i am using -cp switch for any program (even non-database) it gives the error

Error: Could not find or load main class classname

i think i need to solve the problem of why when -cp switch is used the error is thrown
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Sarad!

This looks like a classpath problem, so I'll move it to the Java in General forum.

I'm not that experienced in classpath problems, so I can only comment on the -cp issue: when the classpath contains spaces (as yours does), you need to enclose it in double quotes. Also, individual paths in the classpath must be separated by a semicolon ( ; ), not by a colon ( : ) you have now.
 
Marshal
Posts: 79265
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sarad Mohanan wrote: . . . i set the classpath to . . . by declaring a new environmental variable classpath . . .

That is usually a mistake. Delete that environment variable and always use the -cp option or similar to set your classpath. You can probably set it for the lifetime of a command window with
SET CLASSPATH=.;E:\folder\folder\foo.jar

You may need the . in the classpath so the JVM can find files in the current directory.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic