You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mazur <ma...@raincode.net> on 2001/10/20 18:24:43 UTC
2 Apps, 1 Tomcat
Sort of long....hoping more detail helps...
Tomcat 3.2.3, Apache 1.3.14, RedHat 6.2
I have a problem with class files with the same name being used
by two different apps, both web-browser-based.
I have 2 applications running on the same instance of Tomcat (low
traffic). They both have some class files that have identical
names, but the contents are be mildly different. This seems to
be a problem when I use one app, then go to the other. For
example, if app #1 has a class object called Product.class, and
then I go to app #2 that also uses an object called Product, but
it has different properties/methods, I get an error because my
browser (I *think* my browser is the culprit) is looking for the
first Product object it already used from app#1.
It is obvious I have a configuration problem. But I'm not sure
what the proper resolution is. Here is what I have:
I used to have only one app running, and therefore put all my
class files into webapps/examples/WEB-INF/classes. These classes
would be called from other classes or JSP's with:
import Product;
-or-
<%@ page import = "Product" %>;
All was great. Then I added an application that also uses an
object called Product, but it is different. I elected to put all
classes for this app in a jar file, and put the jar in my
<tomcat_home>/lib directory. All the classes have the line at
the top of the source:
package app2/classes;
...and I have the jar file properly set to have those direcotries
inside. I call the classes in here from other classes or jsp's
with:
import app2.classes.Product;
-or-
<%@ page import = "app2.classes.Product">;
I thought the prefix would be enough to separate the two Product
classes, but they are not. Note that: if I run one app, or the
other app only, they work great. But if I go from one app to
another without first closing my browser and clearing cache, I
get an error saying there is an error with
"app2.classes.Product"...when I am using app#1 and it should only
be using "Product" from app#1, not "app2.classes.Product".
I can certainly see one solution: Make sure ALL classes have
unique names, even if they are from separate apps. But there
must be a better way, or something I am doing wrong. How do you
guys set up 2 apps on one Tomcat instance, when disimilar objects
have the same name?
Thanks,
Rob Mazur
p.s. I hopelessly looked for subject like this in the archive,
but couldn't find any.
Re: 2 Apps, 1 Tomcat
Posted by Anand B N <an...@learningbyte.com>.
Mazur,
Tomcat internally has ways of associating classes to which web-application
they belong to. There are classes of three kinds that get loaded when
Tomcat gets loaded:-
1. Tomcat internal classes - These are the actual classes loaded by default
class loader of the JVM.
2. Common classes - These are classes that are shared across
web-applications/Contexts. These are loaded using a custom class loader
which comes as a part of Tomcat.
3. Web-Application classes - These are loaded using a WebAppClassLoader
which takes care of associating with the correct web-app. A class of one
web-app will not be accessble by another web-app.There are ways to enabling
this in Tomcat but not all servlet engines support them.
The class loading sequence will be similar to the following:-
1. Look in the WEB-INF\lib and WEB-INF\classes
2. If present load it from there for the web-application that's trying to
access it.
3. If not go to CLASSPATH and see if the Class is available.
However you getting error on app2.classes while you are importing only
app1.classes is quite a weird error.
Check out if you have any references to app2.classes in any of your beans
that u use.
I have deployed the same classes with different properties in different
web-applications and have not had a single problem so far. In fact if this
is not supported our companys' primary product goes for a toss :)
Anand
At 08:46 AM 10/21/2001 -0700, you wrote:
>Thanks for responding, Anand.
>
>Ok, so are you suggesting that having the jar files in the
><tomcat_home/lib> directory may be messing things up and I should
>have app1.jar and app2.jar in the
><tomcat_home/webapps/examples/WEB-INF/classes> directory? And
>then each of the jar files should be filled only with classes
>containing the header "package app1.classes" line, or "package
>app2.classes" line (depending on what they belong to)?
>
>I guess I am not sure how Tomcat knows that a certain class is
>part of a certain app. I mean, as far as Tomcat is concerned,
>both app1.jar and app2.jar could both be part of the same
>application, and when it finds Products.class in app1.jar having
>the header "package app1.classes", but my jsp or other class is
>calling for "import app2.classes.Product", I am still going to
>get an error like I am getting right now, won't I?
>
>Thanks,
>Rob
>
>Anand B N wrote:
> >
> > Mazur,
> >
> > There is a way of using the same classes in two different web-apps in
> tomcat.
> >
> > Try making individual JARs of the respective classes for app#1 and app#2
> > and put them in the corresponding WEB-INF/lib
> >
> > or
> >
> > put the classes for each of the web-app in the respective WEB-INF/classes.
> >
> > and remove the jar that u place in TOMCAT_HOME/lib/
> >
> > Tomcat has an web-app class loader that loads classes based on which
> > web-application it belongs to. So even if you have the same Class(same
> > package) in two different web-app the classes are loaded twice and this is
> > how not only tomcat bu all servlet engines should work.
> >
> > In tomcat parlance each of these web-apps are called "Context" and Tomcat
> > always loads a new copy ofthe class if it belongs to a different
> > web-app/Context.
> >
> > Anand
> > At 09:24 AM 10/20/2001 -0700, you wrote:
> > >Sort of long....hoping more detail helps...
> > >
> > >Tomcat 3.2.3, Apache 1.3.14, RedHat 6.2
> > >
> > >I have a problem with class files with the same name being used
> > >by two different apps, both web-browser-based.
> > >
> > >I have 2 applications running on the same instance of Tomcat (low
> > >traffic). They both have some class files that have identical
> > >names, but the contents are be mildly different. This seems to
> > >be a problem when I use one app, then go to the other. For
> > >example, if app #1 has a class object called Product.class, and
> > >then I go to app #2 that also uses an object called Product, but
> > >it has different properties/methods, I get an error because my
> > >browser (I *think* my browser is the culprit) is looking for the
> > >first Product object it already used from app#1.
> > >
> > >It is obvious I have a configuration problem. But I'm not sure
> > >what the proper resolution is. Here is what I have:
> > >
> > >I used to have only one app running, and therefore put all my
> > >class files into webapps/examples/WEB-INF/classes. These classes
> > >would be called from other classes or JSP's with:
> > >import Product;
> > >-or-
> > ><%@ page import = "Product" %>;
> > >
> > >All was great. Then I added an application that also uses an
> > >object called Product, but it is different. I elected to put all
> > >classes for this app in a jar file, and put the jar in my
> > ><tomcat_home>/lib directory. All the classes have the line at
> > >the top of the source:
> > >package app2/classes;
> > >
> > >...and I have the jar file properly set to have those direcotries
> > >inside. I call the classes in here from other classes or jsp's
> > >with:
> > >
> > >import app2.classes.Product;
> > >-or-
> > ><%@ page import = "app2.classes.Product">;
> > >
> > >I thought the prefix would be enough to separate the two Product
> > >classes, but they are not. Note that: if I run one app, or the
> > >other app only, they work great. But if I go from one app to
> > >another without first closing my browser and clearing cache, I
> > >get an error saying there is an error with
> > >"app2.classes.Product"...when I am using app#1 and it should only
> > >be using "Product" from app#1, not "app2.classes.Product".
> > >
> > >I can certainly see one solution: Make sure ALL classes have
> > >unique names, even if they are from separate apps. But there
> > >must be a better way, or something I am doing wrong. How do you
> > >guys set up 2 apps on one Tomcat instance, when disimilar objects
> > >have the same name?
> > >
> > >Thanks,
> > >Rob Mazur
> > >
> > >p.s. I hopelessly looked for subject like this in the archive,
> > >but couldn't find any.
Re: 2 Apps, 1 Tomcat
Posted by Mazur <ma...@raincode.net>.
Thanks for responding, Anand.
Ok, so are you suggesting that having the jar files in the
<tomcat_home/lib> directory may be messing things up and I should
have app1.jar and app2.jar in the
<tomcat_home/webapps/examples/WEB-INF/classes> directory? And
then each of the jar files should be filled only with classes
containing the header "package app1.classes" line, or "package
app2.classes" line (depending on what they belong to)?
I guess I am not sure how Tomcat knows that a certain class is
part of a certain app. I mean, as far as Tomcat is concerned,
both app1.jar and app2.jar could both be part of the same
application, and when it finds Products.class in app1.jar having
the header "package app1.classes", but my jsp or other class is
calling for "import app2.classes.Product", I am still going to
get an error like I am getting right now, won't I?
Thanks,
Rob
Anand B N wrote:
>
> Mazur,
>
> There is a way of using the same classes in two different web-apps in tomcat.
>
> Try making individual JARs of the respective classes for app#1 and app#2
> and put them in the corresponding WEB-INF/lib
>
> or
>
> put the classes for each of the web-app in the respective WEB-INF/classes.
>
> and remove the jar that u place in TOMCAT_HOME/lib/
>
> Tomcat has an web-app class loader that loads classes based on which
> web-application it belongs to. So even if you have the same Class(same
> package) in two different web-app the classes are loaded twice and this is
> how not only tomcat bu all servlet engines should work.
>
> In tomcat parlance each of these web-apps are called "Context" and Tomcat
> always loads a new copy ofthe class if it belongs to a different
> web-app/Context.
>
> Anand
> At 09:24 AM 10/20/2001 -0700, you wrote:
> >Sort of long....hoping more detail helps...
> >
> >Tomcat 3.2.3, Apache 1.3.14, RedHat 6.2
> >
> >I have a problem with class files with the same name being used
> >by two different apps, both web-browser-based.
> >
> >I have 2 applications running on the same instance of Tomcat (low
> >traffic). They both have some class files that have identical
> >names, but the contents are be mildly different. This seems to
> >be a problem when I use one app, then go to the other. For
> >example, if app #1 has a class object called Product.class, and
> >then I go to app #2 that also uses an object called Product, but
> >it has different properties/methods, I get an error because my
> >browser (I *think* my browser is the culprit) is looking for the
> >first Product object it already used from app#1.
> >
> >It is obvious I have a configuration problem. But I'm not sure
> >what the proper resolution is. Here is what I have:
> >
> >I used to have only one app running, and therefore put all my
> >class files into webapps/examples/WEB-INF/classes. These classes
> >would be called from other classes or JSP's with:
> >import Product;
> >-or-
> ><%@ page import = "Product" %>;
> >
> >All was great. Then I added an application that also uses an
> >object called Product, but it is different. I elected to put all
> >classes for this app in a jar file, and put the jar in my
> ><tomcat_home>/lib directory. All the classes have the line at
> >the top of the source:
> >package app2/classes;
> >
> >...and I have the jar file properly set to have those direcotries
> >inside. I call the classes in here from other classes or jsp's
> >with:
> >
> >import app2.classes.Product;
> >-or-
> ><%@ page import = "app2.classes.Product">;
> >
> >I thought the prefix would be enough to separate the two Product
> >classes, but they are not. Note that: if I run one app, or the
> >other app only, they work great. But if I go from one app to
> >another without first closing my browser and clearing cache, I
> >get an error saying there is an error with
> >"app2.classes.Product"...when I am using app#1 and it should only
> >be using "Product" from app#1, not "app2.classes.Product".
> >
> >I can certainly see one solution: Make sure ALL classes have
> >unique names, even if they are from separate apps. But there
> >must be a better way, or something I am doing wrong. How do you
> >guys set up 2 apps on one Tomcat instance, when disimilar objects
> >have the same name?
> >
> >Thanks,
> >Rob Mazur
> >
> >p.s. I hopelessly looked for subject like this in the archive,
> >but couldn't find any.
Re: 2 Apps, 1 Tomcat
Posted by Anand B N <an...@learningbyte.com>.
Mazur,
There is a way of using the same classes in two different web-apps in tomcat.
Try making individual JARs of the respective classes for app#1 and app#2
and put them in the corresponding WEB-INF/lib
or
put the classes for each of the web-app in the respective WEB-INF/classes.
and remove the jar that u place in TOMCAT_HOME/lib/
Tomcat has an web-app class loader that loads classes based on which
web-application it belongs to. So even if you have the same Class(same
package) in two different web-app the classes are loaded twice and this is
how not only tomcat bu all servlet engines should work.
In tomcat parlance each of these web-apps are called "Context" and Tomcat
always loads a new copy ofthe class if it belongs to a different
web-app/Context.
Anand
At 09:24 AM 10/20/2001 -0700, you wrote:
>Sort of long....hoping more detail helps...
>
>Tomcat 3.2.3, Apache 1.3.14, RedHat 6.2
>
>I have a problem with class files with the same name being used
>by two different apps, both web-browser-based.
>
>I have 2 applications running on the same instance of Tomcat (low
>traffic). They both have some class files that have identical
>names, but the contents are be mildly different. This seems to
>be a problem when I use one app, then go to the other. For
>example, if app #1 has a class object called Product.class, and
>then I go to app #2 that also uses an object called Product, but
>it has different properties/methods, I get an error because my
>browser (I *think* my browser is the culprit) is looking for the
>first Product object it already used from app#1.
>
>It is obvious I have a configuration problem. But I'm not sure
>what the proper resolution is. Here is what I have:
>
>I used to have only one app running, and therefore put all my
>class files into webapps/examples/WEB-INF/classes. These classes
>would be called from other classes or JSP's with:
>import Product;
>-or-
><%@ page import = "Product" %>;
>
>All was great. Then I added an application that also uses an
>object called Product, but it is different. I elected to put all
>classes for this app in a jar file, and put the jar in my
><tomcat_home>/lib directory. All the classes have the line at
>the top of the source:
>package app2/classes;
>
>...and I have the jar file properly set to have those direcotries
>inside. I call the classes in here from other classes or jsp's
>with:
>
>import app2.classes.Product;
>-or-
><%@ page import = "app2.classes.Product">;
>
>I thought the prefix would be enough to separate the two Product
>classes, but they are not. Note that: if I run one app, or the
>other app only, they work great. But if I go from one app to
>another without first closing my browser and clearing cache, I
>get an error saying there is an error with
>"app2.classes.Product"...when I am using app#1 and it should only
>be using "Product" from app#1, not "app2.classes.Product".
>
>I can certainly see one solution: Make sure ALL classes have
>unique names, even if they are from separate apps. But there
>must be a better way, or something I am doing wrong. How do you
>guys set up 2 apps on one Tomcat instance, when disimilar objects
>have the same name?
>
>Thanks,
>Rob Mazur
>
>p.s. I hopelessly looked for subject like this in the archive,
>but couldn't find any.