This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes package com.example.model   ERROR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package com.example.model   ERROR" Watch "package com.example.model   ERROR" New topic
Author

package com.example.model ERROR

Steve Bills
Greenhorn

Joined: Feb 19, 2010
Posts: 6
Thank you very for looking at my question...and yes, I have seen this question asked before here.
This is the beloved "Beer" program from Head First Java second edition. I seen some windows solutions...
however, I'm using MacOS X 10.6 via the command line and haven't found a solution that fits what I'm
having trouble with.

...here's my prompt... javac /Library/Tomcat/Home/lib/servlet-api.jar:. classes src/com/example/web/BeerSelect.java


and here are the error codes...

src/com/example/web/BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
error: Class names, 'classes', are only accepted if annotation processing is explicitly requested
src/com/example/web/BeerSelect.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
src/com/example/web/BeerSelect.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();


...the problem is with the import com.example.model.*; I checked my directory and they are
set up properly. I've gone through the code several times and cannot see any incorrect syntax.

any ideas on the fix for this?

Thanks!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Your javac command line is either a huge typo, or you're completely missing the classpath parameter name. Right now you're trying to compile a JAR file.
Steve Bills
Greenhorn

Joined: Feb 19, 2010
Posts: 6
Hi,

Thank you for your replay. hmmm, you were correct about command line arg. It should of read....

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

the book has a javac -classpath /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar:. classes src/com/example/web/BeerSelect.java

the book's author has a different location for his tomcat. He is also using tomcat 5.5 and Java 5. I'm using Tomcat 6 and Java 6. My class is correct, if I do this
command line arg...

javac -classpath /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar:. classes src/com/example/model/BeerExpert.java


...that file will compile flawlessly. any ideas? The BeerSelect.java still cannot find the import com.example.model.*;

Thank you




David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Now you have a spurious 'classes' string in your javac command, unless it's a typo. If you're compiling to a directory named 'classes' then your classpath should include './classes'.
Steve Bills
Greenhorn

Joined: Feb 19, 2010
Posts: 6
i have my development structure set up as follows...

BeerSelect is my project folder. Below that are five folders... etc lib src classes web. in my src folder the structure is src->com->example ...example contains
two folders one called web and and the other is model. My classes folder has a similar structure classes->com->example with example again breaking into
two subfolders called web and model.

My BeerSelect.java file is located in the src/com/example/web/BeerSelect.java - which is how the book has it structured. My BeerExpert.class is located in classes/com/example/model/BeerExpert.class. So when I entered this on the command line...

javac -classpath /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar:. classes src/com/example/model/BeerExpert.java

is classes pointing towards the classes/com/example/model/BeerExpert.class? Should it pointing somewhere else?

once again, thank you!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't think you really understood what I said.See the space? It's bad. Spaces separate command line arguments. It's trying to use a directory as a Java source file, which for obvious reasons, won't work.

As I said before, the classpath should be corrected, to include what I said before: ./classes.
Steve Bills
Greenhorn

Joined: Feb 19, 2010
Posts: 6
Thank you so much. It worked beautifully!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Well done, David, and welcome to the Ranch, Steve Bills
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package com.example.model ERROR
 
Similar Threads
Head First Servlet : Beer Version 2 Problem
Mistakes in HFSJ
Trouble compiling servlet HFSJ pg 85
can't compile a servlet
Ch3 Excercise in HFJS