Setting Classpath for Apache Tomcat Server in Windows 7

In this tutorial, we will look at how to set classpath for the Apache Tomcat server in Windows-7.  I assume that the Apache Tomcat server is already installed on your system.

Setting classpath for servlet API is important for Java server programs or servlets to run. Servlet API is provided by the apache tomcat server as servlet-api. jar file.

If the classpath is not set then compiling java servlet program, will shows errors saying javax.servlet.http package does not exist, this is because of the reason that classpath for the servlet package is not set.

To set the classpath you can select my computer from the desktop, right-click, select properties and click advanced system settings, on the top left corner of the window system property, a dialog box pops up with the Advanced tab selected, click environment variables button, in the environment variables you have two options you can set user variables or you can set system variables, it is better to set classpath in system variables.

You may or may not have classpath variable inside the system’s variable tab, if you already have a classpath variable then you can click edit or else you need to create a new classpath variable by clicking new select the classpath and click Edit the classpath will be under the variable name, next you need to provide the physical path to the servlet-api.jar file

The variables path values, you can type or copy the complete path but it’s better to browse to the location and copy the path to the servlets-api.jar file which is located in the lib folder where the Apache Tomcat server is installed.

The video below demonstrates how to set Classpath for Apache Tomcat Server on Windows-7.


Setting Classpath for Apache Tomcat Server in Windows 7

I have installed the Apache Tomcat server in the D Drive under  Program Files, the servlet-api.jar file is present inside Program Files Apache Software Foundation,  Tomcat, and Lib directory. In some cases depending upon the version of Apache Tomcat server, Lib directory itself may be present in the Commons folder, I am going to copy the entire path from the address bar and append it at the end or at the beginning of the classpath, now I am going to append it at the beginning of the classpath after pasting path till the lib, type backslash followed by servlet-api.jar which is the file name for the Servlets API and then followed by a semicolon to delimit the other path, you can click the ok button, but before that make sure that at the end of the path you have a semicolon and dot, close it by clicking ok, close the environment variables and click OK to close the system properties, close all the command terminals in case they are open, now we can open the command prompt where the servlet file or a servlet program is present and compile the program using javac, you will find no errors, if you get the same error then you need to relook your part to servlet-api.jar file.