You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mark <ma...@telocity.com> on 2001/04/16 16:10:02 UTC

packages under WEB-INF/classes

I have read on this list and in docs if
your servlet class is part of a package,
say com.foo.foobar...that
if you put it in a directory called

$TOMCAT_HOME/webapps/myapp/WEB-INF/classes/com/foo/foobar

assuming the source file has the statement

package com.foo.foobar;

it will be picked up by the class loader and will work.

I have tried this just that way and had this result:

 - Ctx( /foo ): Exception in: R( /foo + /servlet/foo + null)
- java.lang.NoClassDefFoundError: foo (wrong name: com/bar/foobar/foo)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:486)

[remainder of stack dump snipped]

----------------------------------------------------------------------------
--------------------------------------

Yet if I remove the package declaration and put the file
in $TOMCAT_HOME/webapps/myapp/WEB-INF/classes,
it works.

All defaults are being used as far as the configuration files  (ie. for this
example I only added the directory under myapps and added nothing
to tomcat.con or server.xml).

What am I missing?  What is the correct way to add a servlet
that has a package declaration?

Thanks,

Mark



Re: packages under WEB-INF/classes

Posted by Ed Gomolka <eg...@gyldan.com>.
At 10:33 AM 4/16/01 -0400, Mark wrote:
>Sam,
>
>I had no web.xml  for the context.  I was able
>to fix things by adding it.   I guess web.xml
>is not optional in a case like
>this, where the servlet is in a package.  I think
>the FM should be more clear on this.
>
>Thanks a lot for the help!
>
>Mark

The web.xml entry is not required; however, by adding it, you can avoid 
providing the
fully qualified servlet file/path name in your html.

Ed


>----- Original Message -----
>From: "Sam Newman" <sa...@stamplets.com>
>To: <to...@jakarta.apache.org>; "Mark" <ma...@telocity.com>
>Sent: Monday, April 16, 2001 10:15 AM
>Subject: Re: packages under WEB-INF/classes
>
>
> > Does your entry in the web.xml for your context reference the servlet
>using
> > its full path? Also, double check the case of the packages - the entry
> > web.xml, the package declaration and the actual directory strucutre all
>have
> > to match.
> >
> > sam
> > ----- Original Message -----
> > From: "Mark" <ma...@telocity.com>
> > To: <to...@jakarta.apache.org>
> > Sent: Monday, April 16, 2001 3:10 PM
> > Subject: packages under WEB-INF/classes
> >
> >
> > > I have read on this list and in docs if
> > > your servlet class is part of a package,
> > > say com.foo.foobar...that
> > > if you put it in a directory called
> > >
> > > $TOMCAT_HOME/webapps/myapp/WEB-INF/classes/com/foo/foobar
> > >
> > > assuming the source file has the statement
> > >
> > > package com.foo.foobar;
> > >
> > > it will be picked up by the class loader and will work.
> > >
> > > I have tried this just that way and had this result:
> > >
> > >  - Ctx( /foo ): Exception in: R( /foo + /servlet/foo + null)
> > > - java.lang.NoClassDefFoundError: foo (wrong name: com/bar/foobar/foo)
> > >         at java.lang.ClassLoader.defineClass0(Native Method)
> > >         at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
> > >
> > > [remainder of stack dump snipped]
> > >
> >
> > --------------------------------------------------------------------------
> > --
> > > --------------------------------------
> > >
> > > Yet if I remove the package declaration and put the file
> > > in $TOMCAT_HOME/webapps/myapp/WEB-INF/classes,
> > > it works.
> > >
> > > All defaults are being used as far as the configuration files  (ie. for
> > this
> > > example I only added the directory under myapps and added nothing
> > > to tomcat.con or server.xml).
> > >
> > > What am I missing?  What is the correct way to add a servlet
> > > that has a package declaration?
> > >
> > > Thanks,
> > >
> > > Mark
> > >
> > >
> >
> >


Re: packages under WEB-INF/classes

Posted by Mark <ma...@telocity.com>.
Sam,

I had no web.xml  for the context.  I was able
to fix things by adding it.   I guess web.xml
is not optional in a case like
this, where the servlet is in a package.  I think
the FM should be more clear on this.

Thanks a lot for the help!

Mark


----- Original Message -----
From: "Sam Newman" <sa...@stamplets.com>
To: <to...@jakarta.apache.org>; "Mark" <ma...@telocity.com>
Sent: Monday, April 16, 2001 10:15 AM
Subject: Re: packages under WEB-INF/classes


> Does your entry in the web.xml for your context reference the servlet
using
> its full path? Also, double check the case of the packages - the entry
> web.xml, the package declaration and the actual directory strucutre all
have
> to match.
>
> sam
> ----- Original Message -----
> From: "Mark" <ma...@telocity.com>
> To: <to...@jakarta.apache.org>
> Sent: Monday, April 16, 2001 3:10 PM
> Subject: packages under WEB-INF/classes
>
>
> > I have read on this list and in docs if
> > your servlet class is part of a package,
> > say com.foo.foobar...that
> > if you put it in a directory called
> >
> > $TOMCAT_HOME/webapps/myapp/WEB-INF/classes/com/foo/foobar
> >
> > assuming the source file has the statement
> >
> > package com.foo.foobar;
> >
> > it will be picked up by the class loader and will work.
> >
> > I have tried this just that way and had this result:
> >
> >  - Ctx( /foo ): Exception in: R( /foo + /servlet/foo + null)
> > - java.lang.NoClassDefFoundError: foo (wrong name: com/bar/foobar/foo)
> >         at java.lang.ClassLoader.defineClass0(Native Method)
> >         at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
> >
> > [remainder of stack dump snipped]
> >
>
> --------------------------------------------------------------------------
> --
> > --------------------------------------
> >
> > Yet if I remove the package declaration and put the file
> > in $TOMCAT_HOME/webapps/myapp/WEB-INF/classes,
> > it works.
> >
> > All defaults are being used as far as the configuration files  (ie. for
> this
> > example I only added the directory under myapps and added nothing
> > to tomcat.con or server.xml).
> >
> > What am I missing?  What is the correct way to add a servlet
> > that has a package declaration?
> >
> > Thanks,
> >
> > Mark
> >
> >
>
>


Re: packages under WEB-INF/classes

Posted by Sam Newman <sa...@stamplets.com>.
Does your entry in the web.xml for your context reference the servlet using
its full path? Also, double check the case of the packages - the entry
web.xml, the package declaration and the actual directory strucutre all have
to match.

sam
----- Original Message -----
From: "Mark" <ma...@telocity.com>
To: <to...@jakarta.apache.org>
Sent: Monday, April 16, 2001 3:10 PM
Subject: packages under WEB-INF/classes


> I have read on this list and in docs if
> your servlet class is part of a package,
> say com.foo.foobar...that
> if you put it in a directory called
>
> $TOMCAT_HOME/webapps/myapp/WEB-INF/classes/com/foo/foobar
>
> assuming the source file has the statement
>
> package com.foo.foobar;
>
> it will be picked up by the class loader and will work.
>
> I have tried this just that way and had this result:
>
>  - Ctx( /foo ): Exception in: R( /foo + /servlet/foo + null)
> - java.lang.NoClassDefFoundError: foo (wrong name: com/bar/foobar/foo)
>         at java.lang.ClassLoader.defineClass0(Native Method)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
>
> [remainder of stack dump snipped]
>
> --------------------------------------------------------------------------
--
> --------------------------------------
>
> Yet if I remove the package declaration and put the file
> in $TOMCAT_HOME/webapps/myapp/WEB-INF/classes,
> it works.
>
> All defaults are being used as far as the configuration files  (ie. for
this
> example I only added the directory under myapps and added nothing
> to tomcat.con or server.xml).
>
> What am I missing?  What is the correct way to add a servlet
> that has a package declaration?
>
> Thanks,
>
> Mark
>
>