wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Head First Servlets and JSp problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Head First Servlets and JSp problem" Watch "Head First Servlets and JSp problem" New topic
Author

Head First Servlets and JSp problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

176 ,chapter-5

-----------------------------------------
Dog.java location==f:\SC\tomcat\webapps\listenerTest\classes\com\example


----------------------------------------------------------------------
MyServletContextListener .java location==f:\SC\tomcat\webapps\listenerTest\classes\com\example


At cmd,i got :
f:\SC\tomcat\webapps\listenerTest\classes>javac -classpath f:\SC\tomcat\co
mmon\lib\servlet-api.jar com/example/MyServletContextListener.java
com\example\MyServletContextListener.java:12: cannot find symbol
symbol : class Dog
location: class com.example.MyServletContextListener
Dog d=new Dog(dogBreed);
^
com\example\MyServletContextListener.java:12: cannot find symbol
symbol : class Dog
location: class com.example.MyServletContextListener
Dog d=new Dog(dogBreed);
^
com\example\MyServletContextListener.java:12: cannot find symbol
symbol : variable dogBreed
location: class com.example.MyServletContextListener
Dog d=new Dog(dogBreed);
^
3 errors


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Malatesh Karabisti
Ranch Hand

Joined: Jul 28, 2010
Posts: 153

Seems like MyServletContextListener.java class is not able to find the Dog class, have you placed your Dog.class properly in classes directory. please check and try.
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

Dog.class,MyServletContextListener.java and Dog.java are in the same directory
i have checked it
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

I am not sure, but shouldn't you add the current directory to the classpath of javac when you override the default settings?
Also, (not related to the question directly but just a notice) you are missing the WEB-INF directory if you want to deploy the application as a web app:

f:\SC\tomcat\webapps\listenerTest\classes\com\example
f:\SC\tomcat\webapps\listenerTest\WEB-INF\classes\com\example

Cheers!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

i placed Dog.class,MyServletContextListener.java and Dog.java in a separate directory and then tried to compile MyServletContextListener.java .
still getting the same error

if both the classes are in the same package then,why is MyServletContextListener.java not able to create instance of Dog in it's method.
Dog and MyServletContextListener.java are declared public too.
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Mohitkumar, as I said - you didn't add your source directory to the javac classpath.

My directory structure is as follows:

temp
   src
      com
         example
            MyServletContextListener.java
            Dog.java
   bin
      ....


assume 'temp' is your working directory.
When I invoke

javac -cp src:/home/pedro/apache-tomcat-6.0.29/lib/servlet-api.jar src/com/example/MyServletContextListener.java -d bin/

I can compile your example. Please notice the src: which points to the source files directory which are classpath needed for compilation of MySerlvetContextListener class.

Also, check your compilator errors beside the one you posted - you've got
dogBreed variable name at line 11, but you defined the dogbreed variable name at line 10.

Cheers!
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

thanks Pedro
Please notice the src: which points to the source files directory which are classpath needed for compilation of MySerlvetContextListener class.


i didn't get what you mean by theabbove statement
why it is needed to add src directory to classpath ?
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

If you use the -classpath (or -cp) switch explicitely, you are overriding the default settings not adding them.

Please refer to javac command reference guide especially the fragment with says:

The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.


Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Servlets and JSp problem
 
Similar Threads
Error Compiling a Servlet
Package Problem
Compile error
Symbol not found
javac compiling problem