• 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

classpath issue?

 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have this problem....i'm not sure it is classpath issue or what, BUT im sure that my path is correct....please check it for me...thanks

it give me this error when i compile the servlet "BeerSelect.java".


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


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

---------------------
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???

what is the solution???

please give me an idea....i try to fix this problem for 2 days already....
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your src directory is not on the classpath.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, just to expand a little...

By compiling like this:
... classes src/com/example/web/BeerSelect.java
the package create is src.com.example.web and this is not what you want.
 
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

so when i compile, it looks like this

C:\MyProjects\beerV1\src\ > ...-d classes com/example/web/SelectBeer.java

???
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not 100% sure since I haven't read the book. this may be better:

 
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
same result, still saying "package com.example.model does not exist."

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:

1. Compile the model this way from src folder:
javac -d ../classes com/example/model/BeerExpert.java
This will create a folder called classes in the parent directory of src (..) and put com.example.model.BeerSelect class file in that package structure in the created classes directory.

2. Compile the servlet this way from src folder:
javac -classpath /Tomcat_5.5/common/lib/servlet-api.jar -classpath ../classes -d ../classes com/example/web/BeerSelect.java

3. Copy the contents of the classes folder to <your_application_in_server>/WEB-INF/classes folder.

4. When you register this servlet in web.xml, do not forget the full qualified class name (including the package structure)
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the first step does not create a folder named classes, manually create one in the parent directory of src folder before trying these steps.
 
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 Sravan,

i did as you said from step 1 and 2. but step 3 when i compile using exactly what you said, it gave me error like "package javax.servlet does not exist" and the rest of javax.servlet and javax.servlet.http also no exist.

gosh, once this problem not fix, i hardly to continue to chapter 5 of HFSJ.
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Step 3 is only a copy-paste operation to migrate from development to deployment. There is no compilation involved there.

1. Were your packages (com.example.model and com.example.web) recognized when you tried to compile in steps 1 and 2?

2. Try setting the system CLASSPATH to point to servlet-api.jar instead of passing it as an option with javac.
 
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 Sravan,

i know where is the problem already...gosh, i used 2 hours just now to find the wrong path....

my all path of each file and classes did not wrong. i was wrong at this:

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

i forgot to put that BOLD word into the command line....i was such a noob b4.

thanks all for replying. Problem fixed.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I have the same problem as Nicky, I have the system CLASSPATH set to point servlet-api.jar so when I compile I just put javac -d src/com/example/web/BeerSelect.java

How can I introduce the word ;classes; in the statement so I don't have to put the whole path everytime? I'm trying different statements but I still get 'package com.example.model does not exist'
I also tried: javac -classpath servlet-api.jar;classes; -d classes src/com/example/web/BeerSelect.java but then it doesn't find the javax packages too.

Thanks for the help
 
xavi pedros
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my CLASSPATH I got the following:
- D:\java
- C:\...\lib\servlet-api.jar

And my two Java files are here:

- d:\java\servlets\MyProjects\beerV1\src\com\example\web\BeerSelect.java
- d:\java\servlets\MyProjects\beerV1\src\com\example\model\BeerExpert.java

The classes are created there:

- d:\java\servlets\MyProjects\beerV1\classes\com\example\web\BeerSelect.class
- d:\java\servlets\MyProjects\beerV1\classes\com\example\model\BeerExpert.class

I compiled the BeerExpert.java like this:

- javac -classpath servlet-api.jar;classes; -d classes src/com/example/model/BeerExpert.java

And that seems to be ok since no error is shown. But now I'm not able to compile the other class, I tried different things and none runs properly.

EDIT:
The BeerSelect.java have this statement: "import com.example.model.*;" and I get the following error: 'package com.example.model does not exist'

I hope I gave enough information to help me solve the problem. Thanks in advance
 
reply
    Bookmark Topic Watch Topic
  • New Topic