Discussions

Web tier: servlets, JSP, Web frameworks: "package does not exist" error

  1. "package does not exist" error (1 messages)

    Dear members,
    I am developing a Java web project. in my 'src' folder- I have the following two classes:

    1)

    1. package com.foo.model;  
    2. public class BookExpert{  
    3.    //some method implementation  
    4. }  

    2)

    1. package com.foo.controller;  
    2. import com.foo.model.*;  
    3. public class BookSelectServlet extends HttpServlet{  
    4.   public void doPost(HttpServletRequest request, HttpServletResponse response)  
    5.                         throws IOException, ServletException{  
    6.       //calling the model class  
    7.       BookExpert be = new BookExpert();  
    8.   }  
    9. }  

    First, from my project root directory I compiled the model class:
    E:\SCWCD preparation\HF Projects\javaEbook>javac -cp "C:\My Tools\apache-tomcat-
    6.0.20\apache-tomcat-6.0.20\lib\servlet-api.jar" -d classes src\com\foo\model\BookExpert.java

    But later when I tried to compile the controller servlet:
    E:\SCWCD preparation\HF Projects\javaEbook>javac -cp "C:\My Tools\apache-tomcat-
    6.0.20\apache-tomcat-6.0.20\lib\servlet-api.jar" -d classes src\com\foo\controller\BookSelectServlet.java

    I got the following errors:
    src\com\foo\controller\BookSelectServlet.java:8: package com.foo.model does not exist
    import com.foo.model.*;
    ^
    src\com\foo\controller\BookSelectServlet.java:25: cannot find symbol
    symbol : class BookExpert


    though the model class BookExpert was successfully built inside the classes/com/foo/model directory, still the controller servlet did not compile

    please anyone help me out of the pain i am suffering from the last night

  2. 2 things. 

    first, make sure that each package is in its own "folder"

    second, check your path and/or classpaths to make sure that the packages are there.

    Usually when I get an error like the one you are having it turns out to be some typo that I look at a hundred times and don't see. or a "phantom" error,

    a "phantom" error is one that does not show up in the text but is there in the back ground, I solve them by simply retyping the offending code. More times than not, the "error" goes away.

    hope this helps..... some times the problems are ths simplest ones to solve.