• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Package problems

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I am following a tutorial from the Head First servlets & JSPs book (not very well it would appear ).

I am trying to compile this code:


When i do the compile i get these errors:


This is really frustrating as i am following everything word for word in the book.

Does anyone see where i am going wrong?
If i have not given enough info please tell me what you need to help me sort this problem out

Your help would be greatly appreciated.
Thanks,
-Ben
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My package directory is:

com
|
example
|
model

aaaahhhh !

Why is this not working? Pleaase Help me

Thanks,
-Ben
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In what folder are you when you try to compile the class?
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,

if you try to compile your classes in the console window move into the src directory.

Type

javac com/example/web/BeerSelect.java

into the console and press enter.


That should work.

Kind regards
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi thanks for your reply.

My Directory is set up like this (sorry if its a bit confusing this was the best way i could lay it out)

MyProject
|
beerV1
|
classes------|-----src
|-------------------|
com----------------com
|-------------------|
example-----------example
/-----\-------------/----\
web-model-------web-model

The way I am compiling is this:

cd ~/MyProject/beerV1
javac -d classes src/com/example/web/BeerSelect.java

So i have my .java files in the src part of the directory and when i compile them the .class file gets sent to the classes part of the directory

-Ben
[ November 15, 2008: Message edited by: B Crosthwaite ]
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Reinhard,

Thanks for your reply, however i was presented with the same errors when i tried what you said.

Any other ideas?

-Ben
 
Reinhard Horn
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do yo have a file named

BeerExpert.java

in the directory scr/com/example/model?
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.

scr/com/example/model/BeerExpert.java



-Ben
 
Reinhard Horn
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check your directory and file names. Correct spelling, capitalized letters etc..
I get the same errors when I remove BeerExpert.java.
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have checked and double checked

This is very disheartening

Have you managed to compile my code?

-Ben
 
Reinhard Horn
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes but I replaced the Servlet class with a normal class. How did you set the classpath of the servlet.jar file and what OS do you use?
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my classpath is set like this:
CLASSPATH /Library/Tomcat/Home/lib/servlet-api.jar

I am on Mac OS X (version 15.5.5)

Im sorry please can you explain what you mean by "replaced the Servlet class with a normal class" i don't fully understand.

again, thanks for you time. I really appreciate it

-Ben
 
Reinhard Horn
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The errors you get are normal environment errors, meaning there is something wrong with
your directory structure or your file names. It is not a special Servlet problem. The problem would occur also with a "normal" (non Servlet) class. I did not use a servlet class to simplify things. If you want to compile a servlet you must have the servlet jar files in your classpath settings otherwise the complier would not recognize the HttpServlet class.
 
Marshal
Posts: 80266
430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is worth trying compiling the classes one at a time, leaving the class with the main method until last. When you import a class from another package the compiler seems to think that class is already compiled and ready to go.

Or (if there aren't too many classes) compile a list of classes all together

javac mypackage/Class1.java myotherpackage/Class2.java

Or even
javac mypackage/*.java
 
Reinhard Horn
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right. (See compile Xlint Errors). The class file must be in the wrong directory or not existing.
 
Reinhard Horn
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben,

it is the best to simply your steps.

1) make sure that BeerExpert.java is in src/com/example/model
2) make sure that BeerExpert.class is src/com/example/model
3) move to the src directory
4) compile with javac -classpath /Library/Tomcat/Home/lib/servlet-api.jar com/example/model/BeerExpert.java com/example/web/BeerSelect.java
5) move the class files (manually) from the src subdirectories into the classes subdiretories

I tried this successfully. This time with a real Servlet class.

Good luck.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
instead of this
cd ~/MyProject/beerV1
javac -d classes src/com/example/web/BeerSelect.java

try out
cd ~/MyProject/beerV1/src
javac -d classes -cp ../classes com/example/web/BeerSelect.java

For the error in the first post
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Rienhard, Campbell and Vaibhav,

Thanks for all your replys.

Rienhard your steps worked for me, thank you.

-Ben
 
Reinhard Horn
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This might be the better solution:

javac -classpath /Library/Tomcat/Home/lib/servlet-api.jar:.
-d classes src/com/example/web/BeerSelect.java
src/com/example/model/BeerExpert.java

Must be execute in beerV1.
 
Campbell Ritchie
Marshal
Posts: 80266
430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic