• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

package com.example.model.* does not exist ERROR head first servlets

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone i am newbie to this community.I am reading head first servlets .I got an error showing package com.example.model.*; doesnot exist .........
I set my environmental variable classpath as C:\Program Files\Java\jdk1.6.0\lib\tools.jar;C:\Program Files\Java\jdk1.6.0\lib\dt.jar;.;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;%CLASSPATH%;

I can compile BeerExpert.java but i cannot compile BeerSelect.java file

my directory structure for BeerSelect.java is C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\chanti3\WEB-INF\classes\com\example\web\BeerSelect.java

my directory structure for BeerExpert.java is C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\chanti3\WEB-INF\classes\com\example\model\BeerExpert.java


I got the error in the line import com.example.model.*;

can any1 help me?
waiting for your reply

thank you
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinivas, Welcome to JavaRanch . Few things you should get familiar first.

my directory structure for BeerSelect.java is C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\chanti3\WEB-INF\classes\com\example\web\BeerSelect.java

my directory structure for BeerExpert.java is C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\chanti3\WEB-INF\classes\com\example\model\BeerExpert.java


You should never put your source files (for servlets, classes etc..) inside application server as you have done here. Choose different directory outside and put only the compiled class files inside.

I set my environmental variable classpath as C:\Program Files\Java\jdk1.6.0\lib\tools.jar;C:\Program Files\Java\jdk1.6.0\lib\dt.jar


You don't need to set these here.

I got the error in the line import com.example.model.*;


If one of your source files uses any other class file which you compiled those should be accessible in order to compile the class (which is done usually setting a CLASSPATH entry to those packages).
 
srinivas venkat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply

I ill keep my source files in another directory from now onwards


If one of your source files uses any other class file which you compiled those should be accessible in order to compile the class (which is done usually setting a CLASSPATH entry to those packages)

I didnt get your point ......how can i set classpath entry ? how can i solve this problem?
 
Vijitha Kumara
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

......how can i set classpath entry ? how can i solve this problem?



That is, add a CLASSPATH entry just as you have done for the others above pointing to the top level directory which contains your compiled classes (with the correct package heirarchy). This case the directory contains com/example/model.
 
srinivas venkat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help Vijitha Kumara but still the same errors continues package com.example.model doesnot exist ................ i jus changed directories like what you have said...................

i am compiling using the following command

E:\projects\p3>javac -classpath "C:\Program Files\Apache Software Foundation\Tom
cat 5.0\common\lib\servlet-api.jar";"E:\projects\p3\classes\com\example\model";classes:. -d classes src\com\example\web\BeerSelect.java

and my changed directory structure is
E:\projects\p3\src\com\example\model\BeerExpert.java------------this one is compiling and creating .class file at E:\projects\p3\classes\com\example\model\BeerExpert.class
E:\projects\p3\src\com\example\web\BeerSelect.java

the source code for BeerSelect.java is

package com.example.web;
import com.example.model.*; ----------error in importing this
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 IOException,ServletException
{
String c=request.getParameter("color");
BeerExpert be=new BeerExpert();
List result=be.getBrands(c);

response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("Beer Selection Advice <br>");

Iterator it=result.iterator();
while(it.hasNext())
{
out.println("<br>try:"+it.next());
}
}
}

help me out please
 
srinivas venkat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any one there?
 
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

srinivas venkat wrote:any one there?


Please read this and show some patience.
 
Vijitha Kumara
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

srinivas venkat wrote:i am compiling using the following command
E:\projects\p3>javac -classpath "C:\Program Files\Apache Software Foundation\Tom
cat 5.0\common\lib\servlet-api.jar";"E:\projects\p3\classes\com\example\model";classes:. -d classes src\com\example\web\BeerSelect.java



No. I mean you have to add the directory which contains the "com\example\model" to the CLASSPATH, that is "E:\projects\p3\classes\". Try with this & "C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar" as the -classpath entries (remove all the others) and It should compile.

[EDIT]
Or even if you include "classes" in the classpath (with the servlet.jar ofcourse) it should work as it seems you are having the classes directory in the current directory (i.e: the one you are compiling from)
[/EDIT]
 
srinivas venkat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That solved my problem........ i am a beginner started learning servlets and jsps so dont mind if i ask any silly doubts.......Thanks a lot for your help vijitha Kumara ....
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Vijitha Kumara wrote:

srinivas venkat wrote:i am compiling using the following command
E:\projects\p3>javac -classpath "C:\Program Files\Apache Software Foundation\Tom
cat 5.0\common\lib\servlet-api.jar";"E:\projects\p3\classes\com\example\model";classes:. -d classes src\com\example\web\BeerSelect.java



No. I mean you have to add the directory which contains the "com\example\model" to the CLASSPATH, that is "E:\projects\p3\classes\". Try with this & "C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar" as the -classpath entries (remove all the others) and It should compile.

[EDIT]
Or even if you include "classes" in the classpath (with the servlet.jar ofcourse) it should work as it seems you are having the classes directory in the current directory (i.e: the one you are compiling from)
[/EDIT]


Hey i know its been a while since this question was answered, could you please write a full line showing how it would look to to a javac call with both the path to the jar and the path to the dependency class on the same call?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carlos L Sanchez wrote:

Vijitha Kumara wrote:

srinivas venkat wrote:i am compiling using the following command
E:\projects\p3>javac -classpath "C:\Program Files\Apache Software Foundation\Tom
cat 5.0\common\lib\servlet-api.jar";"E:\projects\p3\classes\com\example\model";classes:. -d classes src\com\example\web\BeerSelect.java



No. I mean you have to add the directory which contains the "com\example\model" to the CLASSPATH, that is "E:\projects\p3\classes\". Try with this & "C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar" as the -classpath entries (remove all the others) and It should compile.

[EDIT]
Or even if you include "classes" in the classpath (with the servlet.jar ofcourse) it should work as it seems you are having the classes directory in the current directory (i.e: the one you are compiling from)
[/EDIT]


Hey i know its been a while since this question was answered, could you please write a full line showing how it would look to to a javac call with both the path to the jar and the path to the dependency class on the same call?


beerV1 ~$ javac -classpath /~/apache-tomcat-7.0.96/lib/servlet-api.jar:classes -d classes src/com/example/web/BeerSelect.java
PS:unix use":" windows use ";"
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic