my dog learned polymorphism*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Having problem with importing package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Having problem with importing package" Watch "Having problem with importing package" New topic
Author

Having problem with importing package

Satish Kesiboyana
Greenhorn

Joined: Sep 11, 2005
Posts: 3
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

Joined: Jul 20, 2005
Posts: 215
Hi,

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

Mat
Satish Kesiboyana
Greenhorn

Joined: Sep 11, 2005
Posts: 3
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

Joined: Jul 20, 2005
Posts: 215
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

Joined: Sep 11, 2005
Posts: 3
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

Joined: Jul 20, 2005
Posts: 215
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

Joined: Sep 14, 2005
Posts: 1
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

Joined: Mar 26, 2005
Posts: 378
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???


From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
hi all, my problem fix.
 
jQuery in Action, 2nd edition
 
subject: Having problem with importing package