File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes java programs not running due to seting classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java programs not running due to seting classpath" Watch "java programs not running due to seting classpath" New topic
Author

java programs not running due to seting classpath

Sarad Mohanan
Greenhorn

Joined: May 22, 2012
Posts: 5
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

Joined: Aug 22, 2010
Posts: 3437
    
  47

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

Joined: Oct 13, 2005
Posts: 36508
    
  16
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java programs not running due to seting classpath
 
Similar Threads
not able to connect to the database
JRE Question
Look and Feel
Exception in thread "main" java.lang.NoClassDefFoundError: Test
Servlet compiling problem in tomcat