aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How To Compile Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How To Compile Servlet" Watch "How To Compile Servlet" New topic
Author

How To Compile Servlet

satya mahapatra
Ranch Hand

Joined: Jan 07, 2006
Posts: 134
In chapter3 page 81.
---------------------
javac -classpath /User/bert/Application2. Which path is this.Its written adjust to match your own directory path to your sysytem
I have created my development environment in C:\MyProjects\beerV1 and deployment environment as
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\Beer-v1.


Regards,<br />Satya<br />SCJP,SCWCD
Kaveri Das
Greenhorn

Joined: May 27, 2006
Posts: 11
Originally posted by satya mahapatra:
In chapter3 page 81.
---------------------
javac -classpath /User/bert/Application2. Which path is this.Its written adjust to match your own directory path to your sysytem
I have created my development environment in C:\MyProjects\beerV1 and deployment environment as
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\Beer-v1.


javac -classpath C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar -d<location of your class file> <src-file>
Ken Teoh
Greenhorn

Joined: Jul 20, 2006
Posts: 18
Have the same problem

Do we need the :classes:. after the servlet jar?
It doesn't seem to compile after if I use it.
Mohd Fuzail
Ranch Hand

Joined: Feb 20, 2002
Posts: 107
javac -classpath C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar -d<location of your class file> <src-file>


If you are on windows then please put claspath in double quotes

javac -classpath "C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar" -d<location of your class file> <src-file>


Being defeated is often a temporary condition. Giving up is what makes it permanent.
Ken Teoh
Greenhorn

Joined: Jul 20, 2006
Posts: 18
Tried it without the quotes and it works. However, can some one explain what is the command ":classes:." after the servlet-api.jar is used for? I took it out and it works
satya mahapatra
Ranch Hand

Joined: Jan 07, 2006
Posts: 134
Hi Friends,
Now I am able to compile as I followed all your instructions.
But now the problem is its not taking servlet-api.jar.
satya mahapatra
Ranch Hand

Joined: Jan 07, 2006
Posts: 134
On Compilation its showing error like this
Cant resolve symbol class Httpservlet,HttpservletRequest,ServletException......


FYI................

C:\MyProjects\beerV1>javac -classpath :\ProgramFiles\ApacheSoftwareFoundation\Tomcat5.0\common\lib\servlet-api.jar:classes: -d classes src\com\example\web\Beer
Select.java
src\com\example\web\BeerSelect.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
src\com\example\web\BeerSelect.java:4: package javax.servlet.http does not exist

import javax.servlet.http.*;
^
src\com\example\web\BeerSelect.java:7: cannot resolve symbol
symbol : class HttpServlet
location: class com.example.web.BeerSelect
public class BeerSelect extends HttpServlet{
^
src\com\example\web\BeerSelect.java:9: cannot resolve symbol
symbol : class HttpServletRequest
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest req,HttpServletResponse res)throws Servlet
Exception, IOException{
^
src\com\example\web\BeerSelect.java:9: cannot resolve symbol
symbol : class HttpServletResponse
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest req,HttpServletResponse res)throws Servlet
Exception, IOException{
^
src\com\example\web\BeerSelect.java:9: cannot resolve symbol
symbol : class ServletException
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest req,HttpServletResponse res)throws Servlet
Exception, IOException{
^
6 errors
Ken Teoh
Greenhorn

Joined: Jul 20, 2006
Posts: 18
I got the same problem initially
check the path of your servlet-api.jar
if you're desperate place the jar file in the same directory as your java source file and it should compile
Cai DongShan
Ranch Hand

Joined: Dec 07, 2004
Posts: 102
You should use ; instead of : in Windows system.

Please try the command below.



Best Regards,<br />DongShan<br /> <br />SCJP1.4, SCWCD1.4
satya mahapatra
Ranch Hand

Joined: Jan 07, 2006
Posts: 134
Hi friends i tried all your sugestions. But its still showing same error.
1. Cai DongShan I changed : to ; But it isnt working.

2.Ken Teoh I put the jar file in inside my source file and also inside lib of jdk. Then also not working.

But when I am giving set classpath in command prompt it is showing the servlet-api.jar.

What can be the problems???
I am not able to find out.Anyone faced the similar problems please help.
Cai DongShan
Ranch Hand

Joined: Dec 07, 2004
Posts: 102
satya,

There is not space in the command you post. You create a batch file to include the following lines and try to run the batch file again.

C:
cd \MyProjects\beerV1>
rem copy my command here
satya mahapatra
Ranch Hand

Joined: Jan 07, 2006
Posts: 134
Hi Friends,
At last I got it.What I did is first I uninstall the previous tomcat and again install it and gave the classpath. Now it is working.

To check classpath is working or not we can type command
javap javax.servlet.Servlet

Thanks for all your inputs.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How To Compile Servlet