Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# Compiling a servlet

Rajive Gayan
Greenhorn
Posts: 1
hi im new to the servlet world. I started studing for SCWCD but I cant compile the first example in HF chapter 1 please tell me how to compile a servlet java code Thanks

Sagar Birari
Greenhorn
Posts: 11
You can compile servlet as normal java file..

Regards

Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Rajive,
The first step is to get a copy of the servlets.jar or j2ee.jar. It should come with your server - for example Tomcat or JBoss.

Giovanni De Stefano
Ranch Hand
Posts: 161
Hello

try to give a look here

I assume you followed the instructions on the book.

Basically, if you are compiling from a command line under Windows, you need to know the following folders:

1) where Tomcat is installed (let's assume "c:\Program Files\Tomcat\")
2) where your Project is (let's assume MyProjects\beerv1)

and make sure that JAVA_HOME is set and its bin folder is in the PATH (to check this type echo %JAVA_HOME% and echo %PATH% or simply type javac from the command line and you should get someting).

Once you know this, then you have to:

1) cd MyProjects\beerv1
2) javac -classpath "c:\Program Files\Tomcat\common\lib\servlet-api.jar:classes:." -d classes src\com\example\web\BeerSelect.java

Once you get to the 3rd version, just remember that BeerSelect.java depends on BeerExpert.java, thus you have to compile first BeerExpert and then BeerSelect.

I hope this helps.

Giovanni

Bear Bibeault
Author and ninkuma
Marshal
Posts: 64837
86
Have you read through the FAQ entry for this subject?