File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Problem with importing my own packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with importing my own packages" Watch "Problem with importing my own packages" New topic

Problem with importing my own packages

Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
I'm currently reading HF Servlets & JSP and am having trouble compiling one of their examples at the end of chapter 3. I get an error when I try and compile the program called "BeerSelect" (that is stored in the com.example.web package). The error states that the previously compiled package (called com.example.model) does not exist. I'm following the book so far, but I'm not able to get this last code to compile....

Any ideas or suggestions? I'm sure it has something to do with my classpaths or other environmental settings, but I'm not all that familiar with how they work in concert with the compiler.

Any suggestions would be greatly appreciated.

marc weber

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

When you compile BeerSelect, try adding the classpath to the javac command so that it knows where to find the imported package. For example, if your directory structure is c:\myjava\com\example\model, and your import statement is import com.example.model; then use...

javac -classpath c:\myjava\

(See this section from Thinking in Java for more detail.)
[ February 16, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Jeremy Tartaglia
Ranch Hand

Joined: Mar 11, 2004
Posts: 62
This might sound stupid, but do you have your package in a proper subdirectory? For your package, it would have to be "/com/example/model/" and all the example files from the book in that package would have to be there. If not, you'll have to include the classpath to their location as well. (They still have to be in the proper directory, of course.)
[ February 16, 2006: Message edited by: Jeremy Tartaglia ]
Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
Thanks to both of you for responding. Adding a CLASSPATH environment variable did the trick. This leads me to my next question:

From a configuration management perspective, on large development projects where there are teams of developers, does each developer add their own path to the CLASSPATH on the development machine?

Thanks again. I cna now continue on to the next chapter!

Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
If all the developers work in their private directory, then I think, they all have to set their own classpath in the environment variables.

SCJP 1.4 85%
I agree. Here's the link:
subject: Problem with importing my own packages
It's not a secret anymore!