| Author |
problen in headfirst mvc tutorial
|
muktesh tripathi
Ranch Hand
Joined: Nov 20, 2007
Posts: 30
|
|
I am getting package com.example.model.* package does not exist error when i try to compile the servlet version 2 in mvc tutorial. where as I have followed the developement deployment approach as in the book but it does not let me compile the servlet where as the BeerExpert class compiles ok. PLEASE HELP.... I think my earlier approach of not following developement approach and compiling classes together was nice.... comments please
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2552
|
|
|
"mukteshtripathi "please check your private messages for an important administrative matter. You can see them by clicking the My Private Messages link above.
|
SCJP, SCWCD.
|Asking Good Questions|
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2552
|
|
Will you please let us know what your development and deployment environment is? By this I mean the directory structure. Also I guess you can interpret that " package does not exist error " it means that the package does not exist at all or it cannot be located in the classpath. And welcome to Javaranch
|
 |
muktesh tripathi
Ranch Hand
Joined: Nov 20, 2007
Posts: 30
|
|
My development structure is BeerV1.src.com.example.web.BeerSelect.java and BeerV1.src.com.example.model.BeerExpert.java 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("Reb Moose"); } else{ brands.add("Jail Pale Ale"); brands.add("Gout Scout"); } return (brands); } } package com.example.web; import com.example.model.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; 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("Beer Selecion Advice<br>"); String c = request.getParameter("color"); BeerExpert be = new BeerExpert(); List result = be.getBrands(c); Iterator it = result.iterator(); while(it.hasNext()){ out.print("<br> Try: "+it.next()); } } } to compile BeerExpert.java cd BeerV1 javac -d classes src/com/example/model/BeerExpert.java it lands .class file to right folder correctly. but on compiling BeerSelect cd BeerV1 javac -classpath c:\servlet-api.jar -d classes src/com/example/web/BeerSelect.java it shows package does not exist error.... please help
|
 |
Satish Kandagadla
Greenhorn
Joined: Jul 03, 2006
Posts: 27
|
|
Originally posted by Muktesh Tripathi: My development structure is BeerV1.src.com.example.web.BeerSelect.java and BeerV1.src.com.example.model.BeerExpert.java 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("Reb Moose"); } else{ brands.add("Jail Pale Ale"); brands.add("Gout Scout"); } return (brands); } } package com.example.web; import com.example.model.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; 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("Beer Selecion Advice<br>"); String c = request.getParameter("color"); BeerExpert be = new BeerExpert(); List result = be.getBrands(c); Iterator it = result.iterator(); while(it.hasNext()){ out.print("<br> Try: "+it.next()); } } } to compile BeerExpert.java cd BeerV1 javac -d classes src/com/example/model/BeerExpert.java it lands .class file to right folder correctly. but on compiling BeerSelect cd BeerV1 javac -classpath c:\servlet-api.jar -d classes src/com/example/web/BeerSelect.java it shows package does not exist error.... please help
src is a source folder. In your class the package name starts with com.example.model. Change your directory to src and then try compiling. The error seems to be valid as src is a source folder.
|
 |
muktesh tripathi
Ranch Hand
Joined: Nov 20, 2007
Posts: 30
|
|
I think the problem is with my classpath setting or with my cmd for compiling due to some classpath issue the jvm is not able to find the package in the same directory(probably).. I am not able to figure out the mistake I am making please help
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2552
|
|
The answer is simple, while compiling just as you provide the path for servlet-api.jar, you need to provide the classpath for BeerSelect.java. Hope this helps
|
 |
muktesh tripathi
Ranch Hand
Joined: Nov 20, 2007
Posts: 30
|
|
Thanks for all the help finally I made it(with help from an very old thread on this site only) I had to provide path to COMPILED BeerExpert.class file which was in classes directory after compiling BeerExpert.java working cmd: javac -classpath c:\servlet-api.jar;classes; -d classes src/com/example/web/BeerSelect.java Thanks again
|
 |
 |
|
|
subject: problen in headfirst mvc tutorial
|
|
|