Issue
I am currently new to java and servlets. I am using Apache Tomcat 9.0 as my server and creating the servlets. The error I am getting or the place where I am getting stuck is that when I set CLASSPATH in the system variables as the location of "servlet-api.jar" file the servlet programs compile and run or function properly but not the simple java programs. And the reverse is also true, that is when I remove the CLASSPATH from system variables the servlet programs throw error and the normal java programs compile and run fine. What to do please help.
Solution
You can add your Servlet and other third party jar files in classpath while compiling with "javac" command using the "-cp" option. Below command demonstrate adding two jar files in classpath servlet-api.jar and another.jar while compiling MyFirstServlet.java controller.
javac -cp "/path/to/your/servlet-api.jar:/path/to/your/another.jar;" MyFirstServlet.java
With this approach you do not need to set CLASSPATH in the system variables for your third party jar files.
Answered By - kody-technolab