0

hello!I install tomcat server and set CLASSPATH variable servlet-api and my servlets running properly but when i compile and run my old program program of java 2 SE then it compile successfully but not run it prints an error message

G:\Java>javac BinarySearchDemo.java

G:\Java>java BinarySearchDemo
Error: Could not find or load main class BinarySearchDemo

G:\Java>pause
Press any key to continue . . .

what is problem??????

Edited by peter_budo: Moving to Java web development

3
Contributors
6
Replies
20
Views
2 Years
Discussion Span
Last Post by JamesCherrill
0

Did you set CLASSPATH variable servlet-api, or did you add servlet-api to you classpath?
Maybe the problem is that you lost your previous classpath values?

Edited by JamesCherrill

0

a few other remarks:

  1. applications using servlets are not desktop applications, and should NOT be run using the java <NameOfClass> command.
  2. Java 2 SE became out of date in 2006, you may want to update your study material.
  3. if BinarySearchProgram is not a webapp, then running it should not be influenced by your work on other applications. if it ran before, it should run now.
0

i already said that my programs was running before normally but after tomcat installation this problem is arrise and more thing that when i delete my CLASSPATH then my all programs work properly as it should and my all variable are set like
JAVA_HOME,CATALINE_HOME and CLASSPATHand for compilationPath

0

i think you are not understand that what i am said
i set total four variables

first is only for tomcat CATALINA_HOME
CATALINA_HOME= " C:\apache-tomcat-8.0.15 "

second is also for tomcat JAVA_HOME
JAVA_HOME= " C:\Program Files (x86)\Java\jdk1.7.0_45 "

third is for compilation of JAVA 2 EE programsCLASSPATH
CLASSPATH=" C:\apache-tomcat-8.0.15\lib\servlet-api.jar "

and forth is compilation of my overall programs or JAVA 2 SE programePath
Path=" C:\Program Files (x86)\Java\jdk1.7.0_45\bin "

now problem is that these variables are compile and run only servlet classes if i run only hello world program then it compile as well as but program give run time error message Error: Could not find or load main class BinarySearchDemo
when i remove CLASSPATH variable then program is run as well as but servlets are not run i want that servlets and other programs should run togather i think now it is clear

Edited by moaz.amin.37: editing

0

I did understood that perfectly.

If you didn't have an explicit classpath then you had the default, which is the current working directory. Your new classpath does not include that value, so the current working directory is not in your new classpath, so your class file is not found.

"The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings."
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.