This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Tomcat Compiled Java Beans Clashing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat Compiled Java Beans Clashing" Watch "Tomcat Compiled Java Beans Clashing" New topic

Tomcat Compiled Java Beans Clashing

Soo Yeong Kim

Joined: Nov 06, 2009
Posts: 1

For testing and development purposes, I have 2 webapps in separate locations but with almost identical Java beans. Webapp1 is placed in $TOMCAT_HOME/webapps/ROOT/webapp1/ and its beans are in $TOMCAT_HOME/webapps/ROOT/WEB-INF/classes. Webapp2 is placed in $TOMCAT_HOME/webapps/webapp2/ and its beans are in $TOMCAT_HOME/webapps/webapp2/WEB-INF/classes/. Each of them has a bean called bean1 which has a method called getLoginStatus().

At first I thought the beans for webapp1 were independent of the beans for webapp2, even though they might be named the same, but when I changed getLoginStatus() for webapp2 to getLoginStatus(String), recompile and restart the server, when I run webapp1 there is an exception saying that the getLoginStatus() method can't be found - which means that the JVM is looking at the most recently compiled bean (for which the method signature has changed to getLoginStatus(String)).

So I guess there can only be one bean of the same name loaded at a time? If so, whcih does the JVM pick if there are many to choose from? Could somebody receommend a Tomcat/JSP guide that explains this in detail?

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12755
It sounds like the basic Java class loader to me - once it has found a class with a given package and class name, that is the one it will use.

I suppose you could get involved with custom class loaders but wouldn't it be simpler to use a different package name?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60738

If they are not identical classes, they should not have the same package and class names. That's a recipe for disaster.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
wood burning stoves
subject: Tomcat Compiled Java Beans Clashing
Similar Threads
WebApps not isolated in Tomcat?
JSP can't find bean classes
How to pass Session object between two web apps
How to get another webapp's jndi object from local?
Apache Tomcat/4.0.6 - HTTP Status 500 - Internal Server Error