How to Set ClassPath in Servlet
To set classpath in Servlet you will need to install server and set everything up.
Installation of Server
First of all Download tomcat, remember to choose Tomcat installer version and after finishing download install Tomcat to “Tomcat home directory” regular location for installing Tomcat.
Local of tomcat will be as following :-
C:/program files/apache software foundation/tomcat x.x
Hierarchy of Tomcat Server
Before learning about Tomcat Server and their utilizations you should know description of each folder in installed directory.
- Bin :- Bin folder is switch for Tomcat server, it starts and stops Tomcat server.
- Conf :- Configurations and are saved within this folder with server.xml file and holds all info like configure server port numbers etc.
- Lib :- Lib folder is used to define classpath and store them in servlet-api.jar that helps servlet programming to define classpath for servlet.
- Webapps :- This folder stores all webapps and can be called launchpad of webapps.
Our application requires to set classpath variables for defining path of java classes and it is used by apllication. All required classes for servlet are stored in lib folder with file named as “Servlet-api.jar” and classpath can be set upto that file.
Set Classpath in Servlet
To set classpath in Servlet you will need to copy Servlet Api file’s location and set classpath in environment variable. Find path of Servlet-api.jar.
Classpath variable will require edit if it is already set for core java programming. To edit classpath put semicolon (;) at the end of recent or previous variable and add new location where it is copied without deleting old classpath variable entry.
In below screenshot new path is already defined and you will need to add servlet-api.jar and you will get new path.