File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion 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: 13037
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: 63873

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] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Tomcat Compiled Java Beans Clashing
It's not a secret anymore!