Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with importing my own packages

 
Scott Updike
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Scott
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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\ BeerSelect.java

(See this section from Thinking in Java for more detail.)
[ February 16, 2006: Message edited by: marc weber ]
 
Jeremy Tartaglia
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Scott
 
Aum Tao
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If all the developers work in their private directory, then I think, they all have to set their own classpath in the environment variables.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic