Reputation:
After installing Oracle 11g R2 on my system, I set the environment variable as following:
variable Name :CLASSPATH
variable Value :E:\app\JamesPJ\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar
Variable name : ORACLE_HOME
varaible value :E:\app\JamesPJ\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar
When I run the program using testpad and in command prompt the error comes as follows :
Error: Could not find or load main class test
How is this caused and how can I solve it?
Upvotes: 2
Views: 19684
Reputation: 1109865
Java looks in the classpath for all classes. You've however set the classpath to a single fixed JAR file which is the JDBC driver itself. This JAR file surely doesn't contain your own test.class
file. Provided that your test.class
is available in the current working directory, you should have added the current working directory .
to the classpath.
.;E:\app\JamesPJ\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar
Note that the paths in the classpath are semi colon separated in Windows and colon separated in *nix.
Alternatively, you could also just control the classpath during execution by the -cp
argument. This way the environment variable will be ignored altogether.
java -cp .;E:\app\JamesPJ\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar test
To avoid the tedious work of re-entering the whole command everytime, put it in a .bat
or .cmd
file and execute it instead.
Upvotes: 1