wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes how to set class path 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 set class path" Watch "how to set class path" New topic
Author

how to set class path

Rekha Gaikwad
Ranch Hand

Joined: Jul 25, 2005
Posts: 36
I have installed j2sdk1.4.2_09 and tomcat 5.0.28.exe
how should I set the path and class path.
I have written a simple servlet but when i compile the program i get error (for eg.)can not resolve symbol HttpServlet

pls help me out.
Ner min
Ranch Hand

Joined: Sep 14, 2005
Posts: 76
rightclick my computer on your desktop, chose properties, click on the advenced tab, and then on enviroment variables
set new var CATALINA_HOME=C:\tomcat5(or so)
set new var java_HOME=C:\j2sdk1.4.2_09(or so)
set new var =CLASSPATH=%CATALINA_HOME%\common\lib\servlet-api.jar;%CATALINA_HOME%\common\lib\jsp-api.jar;.;..\classes
add to youre Path var %JAVA_HOME%\bin;
Rekha Gaikwad
Ranch Hand

Joined: Jul 25, 2005
Posts: 36
hey thanks neir..
but are these variable to be declared under system variable or user variable.
Ner min
Ranch Hand

Joined: Sep 14, 2005
Posts: 76
sys of course
Rekha Gaikwad
Ranch Hand

Joined: Jul 25, 2005
Posts: 36
hey thanks Neir, It worked. I can compile servlet..
I am calling servlet from html page. wrote deployment descriptor web.xml and keep it under web-inf directory under tomcat..but my html is not calling servlet..

can u tell me what is the probs?

actually i am using HFSJ and following code in chapter 3.
MI Mohammed
Ranch Hand

Joined: Feb 16, 2005
Posts: 146
Rekha,
I just want give another option, bara borne wayout,
It is not always advicible to alter your system classpath
for security reasons. Learn to use the javac and java -classpath
options.
There is a servlet-api.jar that defines anything servlet.
Check your tomcat common lib for the jar file and add it to the -classpath option and it works. eg

To compile MyServlet.java, the steps;

javac -classpth C:/tomcatDir/common/lib/servlet-api.jar; -d classes MyServlet.java.

make sure you have a classes dir in the same folder, where you servlet is.
The compiler automatically use the package statement to create a file structure for you.

Bareborne, gives you control.

SCJP 1.4 SCJA 1.0


SCJA(Beta) SCJP 1.4 SCWCD 1.4 SCBCD 1.3 SCBCD 5.0 beta <br />The more practice we get, the better we are at the exams and in life in general. Pls join me at My DEN.
Priya Jothi
Ranch Hand

Joined: Jul 13, 2004
Posts: 168
Hi Rekha,

Post ur HTML code & servlet mapping part from web.xml.So that we can see what is wrong in it.

Regards,
Priya.
Rekha Gaikwad
Ranch Hand

Joined: Jul 25, 2005
Posts: 36
thanks Mohammed and priya..

I think probs is with my tomcat settings. Bcz the JSP example comes with tomcat are also not working.

Here is my HTML and web.xml code

html code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<BODY>
<h1 align="center"> Beer selection Page </h1>
<form method="POST"
action="SelectBeer.do">
Select Beer Chracteristics <p>
color:
<select name="color" size="1">
<option>light
<option>amber
<option>brown
<option>dark
</select>
<br><br>
<center>
<input type="SUBMIT">
</center>
</form>

</BODY>
</HTML>


web.xml:


<?xml version="1.0" encoding="ISO-8859-1" ?>


<web-app>


<servlet>
<servlet-name>ch3 Beer</servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>ch3 Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>

</web-app>
Michael Alen Chang
Greenhorn

Joined: Jun 27, 2003
Posts: 9
Hi Rekha,
Where is your servlet class? in your web DD, the BeerSelect.class must place in WEB-INF\classes\com\example\web

Regards,
Michael


Regard,<br />Michael<br />SCJP 1.2, SCJP 1.4, SCWCD 1.3, SCBCD 1.3, SCJA 1.0
Rekha Gaikwad
Ranch Hand

Joined: Jul 25, 2005
Posts: 36
BeerSelect.class is in same directory as u mentioned.
Bimal Patel
Ranch Hand

Joined: Aug 29, 2003
Posts: 130
Hi Rekha,

Can you paste the exception you're getting?


Work Hard, Expect The Worst...<br /> <br />Bimal R. Patel<br />(SCJP 1.2, SCWCD 1.4)
Rekha Gaikwad
Ranch Hand

Joined: Jul 25, 2005
Posts: 36
Guys , my code worked..actually it was minor mistake in class path. thanks for ur support.

Rekha
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to set class path
 
Similar Threads
how to set the path for JMS
How to install J2ME
Class path errors
Class path errors
err message