1 Reply Latest reply: Jun 19, 2010 5:33 PM by 843810 RSS

    package com.example.model does not exist

    843810
      I am on page 82 of Head First and am compiling BeerExpert.



      i created beerexpert.java as following:

      ------------------------------------------------------------------------------------------------------------
      package com.example.model;

      import java.util.*;

      public class BeerExpert {

      public List getBrands(String color) {

      List brands = new ArrayList();

      if (color.equals("amber")) {

      brands.add("Jack Amber");
      brands.add("Red Moose");
      }

      else {

      brands.add("Jail Pale Ale");
      brands.add("Gout Stout");
      }

      return (brands);

      }
      }
      ----------------------------------------------------------------------------------------------------------------


      i compiled this above java file successfully.
      then i created beerselect.java as following:

      -----------------------------------------------------------------------------------------------------------------
      package com.example.web;


      import com.example.model.*;
      import java.io.*;
      import javax.servlet.*;
      import javax.servlet.http.*;
      import java.util.*;


      public class beerselect extends HttpServlet{
      public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException{

      response.setContentType("text/html");
      PrintWriter out=response.getWriter();


      out.println("<h1>Beer selection advice");
      String c=request.getParameter("color");
      beerexpert b=new beerexpert();
      List result=b.getbrands(c);

      //out.println("<br> Got beer color :"+c);
      Iterator i=result.iterator();
      while(i.hasNext()){
      out.print("<br>try:" + i.next());
      }

      }
      }

      --------------------------------------------------------------------------------------------------------------------

      then i used followig commands to compile it:



      E:\MyProjects\beerV1\src\com\example\web> //reached dir where beerselect.java exists.

      E:\MyProjects\beerV1\src\com\example\web>javac beerselect.java


      beerselect.java:4: package com.example.model does not exist
      import com.example.model.*;
      ^
      beerselect.java:20: cannot find symbol
      symbol : class beerexpert
      location: class com.example.web.beerselect
      beerexpert b=new beerexpert();
      ^
      beerselect.java:20: cannot find symbol
      symbol : class beerexpert
      location: class com.example.web.beerselect
      beerexpert b=new beerexpert();
      ^
      3 errors

      ------------------------------------------------------------------------------------------------------------------------
      I have already set environment variables as following:

      CLASSPATH C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar
      JAVA_HOME C:\Program Files\Java\jdk1.6.0
      PATH C:\Program Files\Java\jdk1.6.0\bin

      development environment dir structure is same as depicted in the book.

      one more thing i am not willing to write long classpath in my compiling command. So, is there any way?
      what should i do to remove these errors?
      please help me out.