Hi there,
These are the steps required to compile and deploy a simple servlet in tomcat 7 that is installed on ubuntu.
So initially tomcat has to be installed and the JAVA_HOME variable has to be set.
Next write a simple java servlet progam. For example,
In order to compile this successfully, we have to include the servlet-api.jar. If working_dir is the directory where tomcat is installed , it is present in working_dir/lib.
So this can be done as,
Once this is done, you can compile it normally,
Now that you have the class file, time to deploy on tomcat!!!
Supposing the name of my project is sample, I will have the following hierarchy in tomcat,
working_dir
|
----------------webapps
|
----------------sample
|
-------------WEB-INF
|
|-------classes
|-------lib
|-------web.xml
Here the folder classes contains the class files of our servlet whereas the library folder contains the libraries that are specific to the project.
The web.xml is the configuration of this particular project.
So place the Hello.class in the classes folder. Open web.xml and type in the following,
So this can be done as,
$export CLASSPATH=$CLASSPATH:working_dir/lib/servlet-api.jar
Once this is done, you can compile it normally,
$javac Hello.java
Now that you have the class file, time to deploy on tomcat!!!
Supposing the name of my project is sample, I will have the following hierarchy in tomcat,
working_dir
|
----------------webapps
|
----------------sample
|
-------------WEB-INF
|
|-------classes
|-------lib
|-------web.xml
Here the folder classes contains the class files of our servlet whereas the library folder contains the libraries that are specific to the project.
The web.xml is the configuration of this particular project.
So place the Hello.class in the classes folder. Open web.xml and type in the following,
The servlet name Hello is mapped to the url-pattern /hello, hence we can access using the url pattern, http://localhost:8080/sample/Hello. We also associate it with the class Hello.class.
Now start the tomcat server,
$working_dir/bin/startup.sh
Having done this,go to your browser and type in
http://localhost:8080/sample/Hello
That is about it
aps.
























