• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Having problem with importing package

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all, my problem fix.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic