This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having problem with importing package

 
Satish Kesiboyana
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am preparing for SCWCD from Head First Servlets and JSP and in the 3rd chapter I am stuck with importing package issue:
Hi

I have a java program called "BeerSelect.java" in
c:\myprojects\beerv1\src\com\example\web directory.

I have another program called "BeerExpert.java" in
c:\myprojects\beerv1\src\com\example\model

In BeerSelect.java, I have a code

import com.example.model.*;

at this lne, it gives package does not exist error. I checked the dir .

Please let me know why.

Thanks in advance
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is really a classpath issue. What is your classpath set to?

Mat
 
Satish Kesiboyana
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

My Classpath is
C:\Apache Software Foundation\Tomcat5.0\common\lib\servlet-api.jar

Do I have to use any other class path.
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You will also need 'c:\myprojects\beerv1\src\' in the classpath, so that the compiler can find the package com.example.model

HTH

Mat
 
Satish Kesiboyana
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mat,

Thnx a lot, its working now.

But I had one question...suppose if I had to include 10 user defined packages which are located in 10 different locations, then do I have to include all those package paths in my classpath.

Thnx,

Satish
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satish,

When you compile you do, yes. When you deploy, as long as you use the standard deployment (ie all classes in WEB-INF\classes and all jars in WEB-INF\lib) then no you don't as the container will do that for you.

An easy way arount the problem is to compile all the fairly static classes, that is classes that don't change much and put them into a jar file. Then your classpath will only need one jar file. Alternatively start looking at an IDE such as Eclipse which will do some of that hard work for you.

Mat
 
Geet Bhasker
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was working on the same example, had same problem - the CLASSPATH example works, but the book itself has the correct CLASSPATH which we have overlooked

$CLASSPATH:classes:.

that should cover your bases under your source dir

Geet
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

by the way, i know there is a topic where a guy having problem when compiling "BeerSelect.java" (version 2), stated that :

import com.example.model.*; <---------------give me "package does not exits" error

BeerExpert.java
--------------------------------



BeerSelect.java
------------------



so i am facing the same problem...from yesterday until i try to check, fix...but no solution yet .....is it really classpath issue???

here is my classpath:

servlet-api.jar = C:\Tomcat_5.5\common\lib

BeerSelect.java = C:\MyProjects\beerV1\src\com\example\web

BeerExpert.java = C:\MyProjects\beerV1\src\com\example\model

when i compile:
-------------------------------------
C:\MyProjects\beerV1> javac -classpath /Tomcat_5.5/common/lib/servlet-api.jar -d classes src/com/example/web/BeerSelect.java
-------------------------------------

and it give me "package does not exist" as above mentioned. haiz...where is my classpath wrong???
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all, my problem fix.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic