• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Hi, package compiling question...

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest, thanks again for your help.

-Carmen
 
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic