I really don't understand what I'm doing wrong here..
I'm on chapter 8 of the Java Servlet & JSP Cookbook..
I dl'd the package he says (com.jar) and put it in <webappRoot>/lib..
servlet is here..
C:\tomcat\webapps\file\WEB-INF\classes\com\jspservletcookbook\UploadServlet.class
com.jar is here.. C:\tomcat\webapps\file\WEB-INF\lib
in servlet:
package com.jspservletcookbook;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
import java.util.Enumeration;
public class UploadServlet extends HttpServlet {
// ... etc...
now in this package I dl'd he has it "broken down", so I can see
structure, docs, src, etc in jar file
(cos-05Nov2000\classes\com\oreilly\servlet\multipart).. this is right
code to import that package..
yet when I compile the servlet I get all these errors..
UploadServlet.java:5: package com.oreilly.servlet does not exist
import com.oreilly.servlet.MultipartRequest;
^
UploadServlet.java:6: package com.oreilly.servlet.multipart does not exis
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
^
UploadServlet.java:22: cannot resolve symbol
symbol : class MultipartRequest
location: class com.jspservletcookbook.UploadServlet
MultipartRequest mpr = new MultipartRequest(request,webTempPath,
^
UploadServlet.java:22: cannot resolve symbol
symbol : class MultipartRequest
location: class com.jspservletcookbook.UploadServlet
MultipartRequest mpr = new MultipartRequest(request,webTempPath,
^
4 errors
(I had to recompile b/c had to change this line..
webTempPath = getServletContext().getRealPath("/") + "data";
to
webTempPath = getServletContext().getRealPath("\\") + "data";
make sense? I'm running Tomcat on Windows 2000 (for now... later will
want to make this work on my website server, on unix..)
would appreciate any leads.. thank you.. Frances
Frances Del Rio <fdr58@yahoo.com> said:
>I really don't understand what I'm doing wrong here..
>
>I'm on chapter 8 of the Java Servlet & JSP Cookbook..
>
>I dl'd the package he says (com.jar) and put it in <webappRoot>/lib..
...
>now in this package I dl'd he has it "broken down", so I can see
>structure, docs, src, etc in jar file
>(cos-05Nov2000\classes\com\oreilly\servlet\multipart).. this is right
>code to import that package..
That won't work for a library jar file.
In a library jar file, the directory hierarchy within the jar should
exactly match the package/class hierarchy -- so, for example
>UploadServlet.java:5: package com.oreilly.servlet does not exist
>import com.oreilly.servlet.MultipartRequest;
> ^
... this 'com.oreilly.servlet.MultipartRequest' class file should be
at com/oreilly/servlet/MultipartRequest.class within the jar file.
So, at the minimum you'll need to 'jar xf' (extract) the file you
now have, and 'jar cf' (create) a new jar file, starting from just
below the com/ directory in which the class files are, to get a real
library jar file.

Signature
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
Frances Del Rio - 27 Apr 2005 02:43 GMT
> Frances Del Rio <fdr58@yahoo.com> said:
>
[quoted text clipped - 3 lines]
>>
>>I dl'd the package he says (com.jar) and put it in <webappRoot>/lib..
I made a mistake here.. of course I meant <webappRoot>/WEB-INF/lib..
(which is what I did.....;)
> ...
>>now in this package I dl'd he has it "broken down", so I can see
>>structure, docs, src, etc in jar file
[quoted text clipped - 11 lines]
> ... this 'com.oreilly.servlet.MultipartRequest' class file should be
> at com/oreilly/servlet/MultipartRequest.class within the jar file.
but it is, Juha... in com\oreilly\servlet is a class called
MultipartRequest.class...
in that 'servlet' dir are a bunch of classes AND a dir called 'multipart'...
I "unpacked" jar file in DOS shell, pls see screen-shot here..
http://www.francesdelrio.com/jar.html
so: in <appRoot>WEB-INF/lib should be all these files/dirs that we see
in this screen-shot, right?
if you import a package from a servlet, does Tomcat autom. know to look
for it in WEB-INF/lib?
so if in a servlet that is here..
<appRoot>\WEB-INF\classes\com\jspservletcookbook
I do this..
import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
it should find the package, right?
thank you very much for yr response, Juha.. Frances
Juha Laiho - 27 Apr 2005 19:50 GMT
[ I'm reordering the message a bit - to keep some things better together ]
Frances Del Rio <fdr58@yahoo.com> said:
>> Frances Del Rio <fdr58@yahoo.com> said:
>>
[quoted text clipped - 15 lines]
>>
>> That won't work for a library jar file.
...
>> ... this 'com.oreilly.servlet.MultipartRequest' class file should be
>> at com/oreilly/servlet/MultipartRequest.class within the jar file.
>
>but it is, Juha... in com\oreilly\servlet is a class called
>MultipartRequest.class...
...
>I "unpacked" jar file in DOS shell, pls see screen-shot here..
>http://www.francesdelrio.com/jar.html
[slight grumble about presenting textual info as graphics..]
Ok; I was thrown off by the path you wrote earlier (the one quoted above,
starting with cos-05Nov2000\... ) -- I was assuming that to be the
directory structure within the jar file. What your screen shot showed
was a correct library jar structure.
And now thta I read your other messages as well, you're having problems
at compile time, right? If so, Tomcat is not involved at that point.
So, when compiling a servlet, you'll have to do it manually - and at that
time you need to explicitly tell javac where your libraries are. So,
javac -classpath D:\path\to\some.jar;F:\path\to\other.jar SomeServlet.java
or something like that.
At runtime, Tomcat will find the jar files needed by (compiled) classes,
and at that point it is sufficient to just leave them at WEB-INF\lib.
Was this of any help?

Signature
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
Frances Del Rio - 27 Apr 2005 22:47 GMT
> [slight grumble about presenting textual info as graphics..]
>
[quoted text clipped - 15 lines]
>
> Was this of any help?
oh yes, it was.. thank you so much.. I had to put path to package in
batch file I use to compile.. (also, had missed fact that needed to
alter class in package to put 'package com' at the top (b/c class is now
in WEB-INF\lib\com (instead of in WEB-INF\classes\<package>) and then
had to do a new batch in WEB-INF\lib\com to compile class in package
that will become jar file.. and then after compiling remove src for
class and batch from 'com' dir before I convert to jar.. geeees...
this path-thing to everything can get pretty iffy... ;) now I see why
people use ant and stuff like that, I mean for large apps you can go
crazy here.. (I dl'd ant once but couldn't figure out how to use it..
I guess eventually I will have to..) thank you so much for your help..
Frances
Frances Del Rio - 27 Apr 2005 04:13 GMT
Juha, just as an experiment I packaged a simple helper class I have in
an app.. class is sH.class (simple class that I use just to store vars
to generate HTML code..) I put this class in WEB-INF\lib\com, then
converted this 'com' into a jar.. ('jar cf sH.jar com' in WEB-INF\lib)
so now I have WEB-INF\lib\sH.jar (sH.jar = com\sH.class..) and if in
WEB-INF\lib I do 'jar tf sH.jar' I get
META-INF/
META-INF/MANIFEST.MF
com/
com/sH.class
so far so good, right?
so in servlet (which is in WEB-INF\classes\hm) I now do
import com.sH; but when compiling servlet get told that
'package com.sH' does not exist..
I must be missing something here..
(again, Tomcat knows to look for packages in WEB-INF\lib, right? Juha,
thanks again.. Frances
> Frances Del Rio <fdr58@yahoo.com> said:
>
[quoted text clipped - 27 lines]
> below the com/ directory in which the class files are, to get a real
> library jar file.
Frances Del Rio - 27 Apr 2005 14:42 GMT
> Juha, just as an experiment I packaged a simple helper class I have in
> an app.. class is sH.class (simple class that I use just to store vars
[quoted text clipped - 18 lines]
> (again, Tomcat knows to look for packages in WEB-INF\lib, right? Juha,
> thanks again.. Frances
ok, I think mistake I made is I gave package same name as class inside
'com' dir.. what I did now: in WEB-INF\lib I have com\sH.class, so:
to create jar file: "jar cf html.jar com", which, when I do
"jar tf html.jar" returns:
META-INF/
META-INF/MANIFEST.MF
com/
com/sH.class
in servlet (in WEB-INF\classes\hm) I do
import com.sH;
yet when I compile I get told 'package com doesn't exist'..
now I REALLY don't know what I am doing wrong.. would appreciate
leads... thank you... Frances
Rivky - 27 Apr 2005 19:02 GMT
are u trying to compile the servlet or run/access thru browser the
servlet?
If you are just trying to compile -
I think maybe the issue is not in the package structure. it's in the
compiling tool you're using. How are you compiling your code? Make sure
that the jar is in your classpath or if you're using one of the
standard IDE's. that you have it listed, with the correct path, as one
of the required libraries.