• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java programs not running due to seting classpath

 
Sarad Mohanan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49865
71
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic