• 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

"package does not exist" message in servlet

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I created a Package which includes a bean in directory c:\classes\packagex\utility\bean.class. at the top of the bean I put the line "package packagex.utility;". I then created a servlet which is in directory c:\classes\packagex\servlets\servlet.class, on the top of the servlet I have "package packagex.servlet;".
The error I get is when in the servlet i try to import the bean package using "import packagex.utility.*;" I get an error "package packagex.utility not found".
Please help if you have any ideas.
Thank you
Michael
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
check out your classpath & try out.
 
michael shay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have it in the classpath, but am still getting that error.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what directory are you in when you attempt to compile, and what is the exact command you send to javac ?
 
michael shay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In directory c:\classes\packagex\servlets\" that is where the servlet that I am trying to compile is located.
I use "javac sevlet.java"
thanks for your help
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hate debugging classpath issues, especially when they're my own. So I figured out a while back the way to avoid them is to use the command-line switch to send in a classpath. There is a second switch to tell where to place the compiled classes. This has been a godsend. If you're not using ANT, at least try this out...

within WEB-INF have two directories...

all of my code is in the src directory, but there are no subfolders here. So even if my class is in a package, I don't worry about it for the source file.

I use Textpad as my java 'IDE', and my javac macro looks like:

-classpath c:\jars\servlet.jar;..\classes;%CLASSPATH% -d ..\classes $File

What this does is several things. First, you're absolutely specifying where to find servlet.jar. Then, you are also specifying where to find any of your own files (that's the ..\classes part). Why are they there? That's the second cool thing. The -d ..\classes option tells javac to transfer your compiled class files into the classes directory... and the added benefit is that it will put them in the appropriate folder heirarchy (into their packages).

How does this help you? If for example, you placed the source for both your bean and servlet class into the src directory, and compiled the bean class first, you'd find it appearing in classes\packagex\utility\bean.class

Then when your servlet tries to import it, it should find it, because you are sending it ..\classes with the -cp switch.

This has worked for me for quite a while. And from project to project, you don't need to change your settings in Textpad, as long as you always have a src and classes directory at the same level (and compile from the root of src)
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic