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??????

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?

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.

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

You just need to ADD servkey-api to your classpath, keeping all the existing entries as well.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.