wood burning stoves 2.0*
The moose likes Java in General and the fly likes Hi, package compiling question... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Hi, package compiling question..." Watch "Hi, package compiling question..." New topic
Author

Hi, package compiling question...

Carmen Brianick
Ranch Hand

Joined: Feb 23, 2006
Posts: 67
Hi, I have two classes both inside the same package, Dog.java and MyServletContextListener.java inside C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\Beer-v1\WEB-INF\classes\com\example directory. I can compile Dog but when I try to compile MyServletContextListener.java, I get the error "cannot resolve symbol symbol : class Dog

I have pasted my java code below and this is the command that I am using:
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\Beer-v1\WEB-INF>
javac -classpath lib/servlet-api.jar;. -d classes classes/com/example/MyServletContextListener.java

Am I doing something wrong in the command line or code?

//Dog.java
package com.example;
public class Dog{
private String breed;
public Dog(String breed){this.breed = breed;}
}

//MyServletContextListener.java
package com.example;
import javax.servlet.*;
public class MyServletContextListener implements ServletContextListener{
public void contextInitialized(ServletContextEvent event){
ServletContext sc = event.getServletContext();
String dogBreed = sc.getInitParameter("breed");
Dog d = new Dog(dogBreed);
sc.setAttribute("dog", d);
}
public void contextDestroyed(ServletContextEvent event){
}
}

Thanks so much for your great help!
Carmen
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The compiler can't find the other class, because it's going to look along its classpath for a "com" directory. It's not going to find one -- it's going to find only the "classes" directory, which isn't good enough. The most straightforward way to address this would be to add WEB-INF/classes, rather than WEB-INF, to the classpath switch.


[Jess in Action][AskingGoodQuestions]
Carmen Brianick
Ranch Hand

Joined: Feb 23, 2006
Posts: 67
Hi Ernest, thanks so much for your reply! I actually tried this and it worked: javac -classpath classes;lib/servlet-api.jar; -d classes classes/com/example/MyServletContextListener.java

Inside WEB-INF, I triend javac -classpath lib/servlet-api.jar; com/example/MyServletContextListener.java

Ernest, I was wondering if you can tell me what command did you suggest using?

Thanks so much,
Carmen
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

I was suggesting your first option. Your second option would also work if you added "." (dot), which always represents the current directory, to the classpath argument.
Carmen Brianick
Ranch Hand

Joined: Feb 23, 2006
Posts: 67
Hi Ernest, thanks again for your help.

-Carmen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hi, package compiling question...
 
Similar Threads
HFS page 171
Package Problem
Head First Servlets and JSp problem
Problem importing Dog class
Symbol not found