File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Compiling a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compiling a servlet" Watch "Compiling a servlet" New topic

Compiling a servlet

Rajive Gayan

Joined: Nov 07, 2006
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

Joined: Sep 05, 2008
Posts: 11
You can compile servlet as normal java file..
explain your exact problem


Sagar Birari
Development & Technical Blog
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Giovanni De Stefano
Ranch Hand

Joined: Aug 17, 2004
Posts: 154

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\

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

I hope this helps.


SCJP 1.4
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

Have you read through the FAQ entry for this subject?

[Asking smart questions] [About Bear] [Books by Bear]
Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2851

Hi Rajive Gayan welcome to Javaranch ,

The FAQ entry Bear is talking about can be found here .
Just to check whether all things are in place(that means your server) try experimenting with the CodeBarnSimpleServlet .
If you see "Hello, World" then as Giovanni says, you need to follow the steps in his post to make your servlet compile and run.

Hope this helps

|Asking Good Questions|
I agree. Here's the link:
subject: Compiling a servlet
jQuery in Action, 3rd edition