Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hi, package compiling question...

 
Carmen Brianick
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Carmen Brianick
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest, thanks again for your help.

-Carmen
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic