You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by yilmaz <yi...@hwajet.com.tw> on 2001/08/23 06:22:11 UTC

a simple ( irritating) classpath problem

hi all,
i have been using servlets and tomcat for a long time
but till now i couldn't figure out how to set the classpath exactly
Can some one please explain this briefly and clearly?
you might ask "how did you use tomcat without setting the classpath"
each time i used trial and error method, because the descriptions in docs
never seems to work correctly.
But at last i decided to solve this problem radically, becasue i am already
sick of classpath problems
first let me explain what my problem is:

I developed a message board using servlets
it works fine , but only with the default  charset.
namely, when users enters local charset (e.g: big5 chinese), my servlet
can't recognize these chars,
so only some question marks are stored into the database.
i tried to solve this problem with all kinds of methods available, but none
of them worked.
i tried servlet interest group, it didn't work either.
At last I used the ParameterParser class  of the oreilly package as
described in Jason's book(java servlet programming)
it worked, but i had a lot of trouble with the classpath settings
But still i don't know how to set it up,  beacause it started   not to work
again.
Simply when i compile my servlet it doesn't recognize parameterparser class,
saying that it is not on classpath
IT IS VERY IRRITATING
because i put all the package (com.oreilly.servlet.*) in the same directory
with the servlet (under web-inf/classes/ com/servlet/  directory)
i tried putting the cos.jar file in the web-inf/lib directory, it didn't
work
in put these files directly under the web-inf/classes/   directory , it
didn't work either
according to docs, all the classes are in the classpath by default, so the
compiler supposed to find these classes, but it can't
then i added the full path <tomcat_home>/lib/cos.jar, to the classpath,
didn't work either.
well, i gave up, i just wanted to learn the LOGICAL way to set the classpath
up.
PLEASE help me
by the i am using tomcat 4 ( already switched from tomcat 3.2.2), my OS is
win 2000, JDK is 1.3
i am sick of seraching the docs every time when i have the same problem
i am looking forward to your help as soon as possible
THANK  YOU FOR YOUR KINDNESS IN ADVANCE
BEST REGARDS



Re: a simple ( irritating) classpath problem

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 23 Aug 2001, Jonathan Eric Miller wrote:

> Date: Thu, 23 Aug 2001 08:38:50 -0500
> From: Jonathan Eric Miller <to...@shark.uchicago.edu>
> Reply-To: tomcat-user@jakarta.apache.org
> To: tomcat-user@jakarta.apache.org
> Subject: Re: a simple ( irritating) classpath problem
>
>
> ----- Original Message -----
> From: "Dmitri Colebatch" <di...@bigpond.net.au>
> To: <to...@jakarta.apache.org>
> Sent: Wednesday, August 22, 2001 11:33 PM
> Subject: Re: a simple ( irritating) classpath problem
>
>
> > hi,
> >
> > There are three basic areas that classes can be put in tomcat:
> >
> > WEB-INF/classes
> >   - contains all the classes that form the web application
> > WEB-INF/lib
> >   - contains jars that the web application uses
> > TOMCAT_HOME/lib
> >   - contains jars that are available to _all_ applications using tomcat
>
> There's one other one that I came across yesterday as well.
>
> TOMCAT_HOME/server/lib
>
> I think this is probably Tomcat 4 specific,

Yes, it is.

> not sure. I found that in order
> to get JDBCRealm to work, I had to copy the .jar file for my JDBC driver to
> this directory. Note, it didn't work when I first tried copying it to
> TOMCAT_HOME/lib.
>

That's correct.  JAR files in this directory are made available to the
internal Tomcat classes -- and that's what JDBCRealm is, so it needs to
have access to the JDBC driver you want to use.

> Jon
>
>
>

Craig



Re: a simple ( irritating) classpath problem

Posted by Jonathan Eric Miller <to...@shark.uchicago.edu>.
----- Original Message -----
From: "Dmitri Colebatch" <di...@bigpond.net.au>
To: <to...@jakarta.apache.org>
Sent: Wednesday, August 22, 2001 11:33 PM
Subject: Re: a simple ( irritating) classpath problem


> hi,
>
> There are three basic areas that classes can be put in tomcat:
>
> WEB-INF/classes
>   - contains all the classes that form the web application
> WEB-INF/lib
>   - contains jars that the web application uses
> TOMCAT_HOME/lib
>   - contains jars that are available to _all_ applications using tomcat

There's one other one that I came across yesterday as well.

TOMCAT_HOME/server/lib

I think this is probably Tomcat 4 specific, not sure. I found that in order
to get JDBCRealm to work, I had to copy the .jar file for my JDBC driver to
this directory. Note, it didn't work when I first tried copying it to
TOMCAT_HOME/lib.

Jon



Re: a simple ( irritating) classpath problem

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 23 Aug 2001, yilmaz wrote:

> Date: Thu, 23 Aug 2001 14:12:54 +0800
> From: yilmaz <yi...@hwajet.com.tw>
> Reply-To: tomcat-user@jakarta.apache.org
> To: tomcat-user@jakarta.apache.org
> Subject: Re: a simple ( irritating) classpath problem
>
> thanks Dimitri
> but that is what i exactly did, and (of course) i imported oreily package
> at the beginning with ( import com.oreilly.servlet.*; )
> but all those efforts are in vain, i don't understand it.
> when i reference this ParameterParser file with fulll path it works
> like:
> com.oreilly.servlet.ParameterParser parser=new
> com.oreilly.servlet.ParameterParser ;
> this works,
> but why don't the others work.
> i put this packet under both <tomcat_home>/lib/cos.jar,
> <tomcathome>webapps/root/web-inf/classes/com/oreilly/servlet/ and as well as
> <tomcathome>webapps/root/web-inf/lib/ but still Doesn't work, simply i can't
> compile
> becasue it keeps telling me  ParameterParser is not on the classpath
> any ideas please ( i used tomcat 4 and tomcat 3.2.2 ) they both behave the
> same way
> thanks for your help

It sounds like part of your frustration is related to the fact that you
are using classpaths for two different things -- *compiling* your servlets
and *running* Tomcat.  They are two different needs, and often require two
different values.

One suggestion is to set up your development environment to use Ant 1.3,
and let it take care of class path problems for you.  Instructions on how
to do this are in the Tomcat 4 version of the Tomcat "Application
Developer's Guide", which can be found online at:

  http://jakarta.apache.org/tomcat/tomcat-4.0-doc-exp/appdev/index.html

Nowdays, I routinely build and run webapps (and even Tomcat 4 itself) with
*nothing* in my CLASSPATH variable.  Whenever I need a classpath build, I
just tell Ant to do it for me.  Whenever I want a library JAR available in
Tomcat, I just drop it into the top-level "lib" directory.  Life is a lot
less frustrating if you let tools do some of the work for you.

Craig McClanahan


Re: a simple ( irritating) classpath problem

Posted by yilmaz <yi...@hwajet.com.tw>.
HI ALL,
first of all thanks for everybody for your help
those garbled chars you see on your email are chinese characters(big5)
but i already translated it for those  who may not be able to see
(understand)them
it says ParameterParser is not on the right classpath
Any way guys , finally after a lot of trial and error methods i managed to
make my
Tomcat to recognize ParameterParser
However, i am stil confused and didn't understand the logic behind the
classpath setting
because it seems to me that previously i had already done the same settings,
but it ididn't work
now it works.
So i think the best idea is (as Craig  said)  "One suggestion is to set up
your development environment to use Ant 1.3,
and let it take care of class path problems for you"
i will try this method, otherwise handling classpath problems is really
wasting time
it takes longer time to set the classpath than developing the real
application
THANKS AGAIN TO EVRYBODY
CHEERS  =)



----- Original Message -----
From: "Dmitri Colebatch" <di...@bigpond.net.au>
To: <to...@jakarta.apache.org>
Sent: Friday, August 24, 2001 8:16 AM
Subject: Re: a simple ( irritating) classpath problem


On Thu, 23 Aug 2001, yilmaz wrote:
>
> D:\tomcat4\jakarta-tomcat-4.0-b7\webapps\ROOT\WEB-INF\classes>javac
gs.java
> gs.java:37: 不能??ParameterParser
> ?��???�件�?\ParameterParser.class
> ??�件?��?????:com.oreilly.servlet.ParameterParser
> ??��??�确信�????�正确�?classpath?��???�?
>      ParameterParser parser= new ParameterParser(req);
>      ^
> 1 ???

What are all those weird characters?  Not sure if they are doing anything
weird... other than that - I'm out of ideas

cheers
dim



Re: a simple ( irritating) classpath problem

Posted by Dmitri Colebatch <di...@bigpond.net.au>.
On Thu, 23 Aug 2001, yilmaz wrote:
> 
> D:\tomcat4\jakarta-tomcat-4.0-b7\webapps\ROOT\WEB-INF\classes>javac gs.java
> gs.java:37: 不能??ParameterParser
> 坏的?文件:.\ParameterParser.class
> ?文件含有??的?:com.oreilly.servlet.ParameterParser
> ?去掉或确信它出?在正确的classpath的子目?中.
>      ParameterParser parser= new ParameterParser(req);
>      ^
> 1 ???

What are all those weird characters?  Not sure if they are doing anything
weird... other than that - I'm out of ideas

cheers
dim



Re: a simple ( irritating) classpath problem

Posted by yilmaz <yi...@hwajet.com.tw>.
here is the related part of my code:
import java.io.*;
import java.sql.*;
import java.text.DateFormat;
import java.util.*;
import java.lang.Math;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.*;
public class gs extends HttpServlet {

.....
 try {
     ParameterParser parser= new ParameterParser(req);
    parser.setCharacterEncoding("big5");
     subject=parser.getStringParameter("subject");

..........

and the compiler gives me the following error:

D:\tomcat4\jakarta-tomcat-4.0-b7\webapps\ROOT\WEB-INF\classes>javac gs.java
gs.java:37: 不能??ParameterParser
坏的?文件:.\ParameterParser.class
?文件含有??的?:com.oreilly.servlet.ParameterParser
?去掉或确信它出?在正确的classpath的子目?中.
     ParameterParser parser= new ParameterParser(req);
     ^
1 ???
simply it says that com.oreilly.servlet.ParameterParser is not on the
classpath
Strange,  ISN'T it?
cheers :)
----- Original Message -----
From: "Dmitri Colebatch" <di...@bigpond.net.au>
To: <to...@jakarta.apache.org>
Sent: Thursday, August 23, 2001 2:24 PM
Subject: Re: a simple ( irritating) classpath problem


> On Thu, 23 Aug 2001, yilmaz wrote:
> > but all those efforts are in vain, i don't understand it.
> > when i reference this ParameterParser file with fulll path it works
> > like:
> > com.oreilly.servlet.ParameterParser parser=new
> > com.oreilly.servlet.ParameterParser ;
> > this works,
>
> if that works then its not a classpath problem, but an import
> problem.  Are you sure you haven't got a simple typo or something?  post
> your code and we'll have a look (o:
>
> cheers
> dim
>
>
>



Re: a simple ( irritating) classpath problem

Posted by Dmitri Colebatch <di...@bigpond.net.au>.
On Thu, 23 Aug 2001, yilmaz wrote:
> but all those efforts are in vain, i don't understand it.
> when i reference this ParameterParser file with fulll path it works
> like:
> com.oreilly.servlet.ParameterParser parser=new
> com.oreilly.servlet.ParameterParser ;
> this works,

if that works then its not a classpath problem, but an import
problem.  Are you sure you haven't got a simple typo or something?  post
your code and we'll have a look (o:

cheers
dim


> but why don't the others work.
> i put this packet under both <tomcat_home>/lib/cos.jar,
> <tomcathome>webapps/root/web-inf/classes/com/oreilly/servlet/ and as well as
> <tomcathome>webapps/root/web-inf/lib/ but still Doesn't work, simply i can't
> compile
> becasue it keeps telling me  ParameterParser is not on the classpath
> any ideas please ( i used tomcat 4 and tomcat 3.2.2 ) they both behave the
> same way
> thanks for your help
> ----- Original Message -----
> From: "Dmitri Colebatch" <di...@bigpond.net.au>
> To: <to...@jakarta.apache.org>
> Sent: Thursday, August 23, 2001 12:33 PM
> Subject: Re: a simple ( irritating) classpath problem
> 
> 
> > hi,
> >
> > There are three basic areas that classes can be put in tomcat:
> >
> > WEB-INF/classes
> >   - contains all the classes that form the web application
> > WEB-INF/lib
> >   - contains jars that the web application uses
> > TOMCAT_HOME/lib
> >   - contains jars that are available to _all_ applications using tomcat
> >
> > > because i put all the package (com.oreilly.servlet.*) in the same
> directory
> > > with the servlet (under web-inf/classes/ com/servlet/  directory)
> >
> > if it is the package com.oreilly.servlet then it should go in
> > WEB-INF/classes/com/oreilly/servlet - even better, I assume you got it as
> > a jar, just put the jar in WEB-INF/lib .  If it is a zip, then rename it
> > to a jar.
> >
> > > i tried putting the cos.jar file in the web-inf/lib directory, it didn't
> > > work
> >
> > what do you mean it didn't work?  try jar -tf cos.jar to check that the
> > classes are in the jar.  I assume you are importing the required classes
> > and that they exist in the jar.
> >
> > > in put these files directly under the web-inf/classes/   directory , it
> > > didn't work either
> >
> > again, should be according to package
> >
> > > then i added the full path <tomcat_home>/lib/cos.jar, to the classpath,
> > > didn't work either.
> >
> > I'm not sure why that didn't work - although if you put cos.jar in the
> > classpath it _should_ be available to all web applications.
> >
> > > well, i gave up, i just wanted to learn the LOGICAL way to set the
> classpath
> > > up.
> >
> > you dont need to set the classpath yourself.  just put your jars in
> > WEB-INF/lib and your classes in WEB-INF/classes
> >
> > hth, cheers
> > dim
> >
> >
> 
> 
> 


Re: a simple ( irritating) classpath problem

Posted by yilmaz <yi...@hwajet.com.tw>.
thanks Dimitri
but that is what i exactly did, and (of course) i imported oreily package
at the beginning with ( import com.oreilly.servlet.*; )
but all those efforts are in vain, i don't understand it.
when i reference this ParameterParser file with fulll path it works
like:
com.oreilly.servlet.ParameterParser parser=new
com.oreilly.servlet.ParameterParser ;
this works,
but why don't the others work.
i put this packet under both <tomcat_home>/lib/cos.jar,
<tomcathome>webapps/root/web-inf/classes/com/oreilly/servlet/ and as well as
<tomcathome>webapps/root/web-inf/lib/ but still Doesn't work, simply i can't
compile
becasue it keeps telling me  ParameterParser is not on the classpath
any ideas please ( i used tomcat 4 and tomcat 3.2.2 ) they both behave the
same way
thanks for your help
----- Original Message -----
From: "Dmitri Colebatch" <di...@bigpond.net.au>
To: <to...@jakarta.apache.org>
Sent: Thursday, August 23, 2001 12:33 PM
Subject: Re: a simple ( irritating) classpath problem


> hi,
>
> There are three basic areas that classes can be put in tomcat:
>
> WEB-INF/classes
>   - contains all the classes that form the web application
> WEB-INF/lib
>   - contains jars that the web application uses
> TOMCAT_HOME/lib
>   - contains jars that are available to _all_ applications using tomcat
>
> > because i put all the package (com.oreilly.servlet.*) in the same
directory
> > with the servlet (under web-inf/classes/ com/servlet/  directory)
>
> if it is the package com.oreilly.servlet then it should go in
> WEB-INF/classes/com/oreilly/servlet - even better, I assume you got it as
> a jar, just put the jar in WEB-INF/lib .  If it is a zip, then rename it
> to a jar.
>
> > i tried putting the cos.jar file in the web-inf/lib directory, it didn't
> > work
>
> what do you mean it didn't work?  try jar -tf cos.jar to check that the
> classes are in the jar.  I assume you are importing the required classes
> and that they exist in the jar.
>
> > in put these files directly under the web-inf/classes/   directory , it
> > didn't work either
>
> again, should be according to package
>
> > then i added the full path <tomcat_home>/lib/cos.jar, to the classpath,
> > didn't work either.
>
> I'm not sure why that didn't work - although if you put cos.jar in the
> classpath it _should_ be available to all web applications.
>
> > well, i gave up, i just wanted to learn the LOGICAL way to set the
classpath
> > up.
>
> you dont need to set the classpath yourself.  just put your jars in
> WEB-INF/lib and your classes in WEB-INF/classes
>
> hth, cheers
> dim
>
>



Re: a simple ( irritating) classpath problem

Posted by Dmitri Colebatch <di...@bigpond.net.au>.
hi,

There are three basic areas that classes can be put in tomcat:

WEB-INF/classes
  - contains all the classes that form the web application
WEB-INF/lib
  - contains jars that the web application uses
TOMCAT_HOME/lib
  - contains jars that are available to _all_ applications using tomcat

> because i put all the package (com.oreilly.servlet.*) in the same directory
> with the servlet (under web-inf/classes/ com/servlet/  directory)

if it is the package com.oreilly.servlet then it should go in
WEB-INF/classes/com/oreilly/servlet - even better, I assume you got it as
a jar, just put the jar in WEB-INF/lib .  If it is a zip, then rename it
to a jar.

> i tried putting the cos.jar file in the web-inf/lib directory, it didn't
> work

what do you mean it didn't work?  try jar -tf cos.jar to check that the
classes are in the jar.  I assume you are importing the required classes
and that they exist in the jar.

> in put these files directly under the web-inf/classes/   directory , it
> didn't work either

again, should be according to package

> then i added the full path <tomcat_home>/lib/cos.jar, to the classpath,
> didn't work either.

I'm not sure why that didn't work - although if you put cos.jar in the
classpath it _should_ be available to all web applications.

> well, i gave up, i just wanted to learn the LOGICAL way to set the classpath
> up.

you dont need to set the classpath yourself.  just put your jars in
WEB-INF/lib and your classes in WEB-INF/classes

hth, cheers
dim