wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat Compiled Java Beans Clashing" Watch "Tomcat Compiled Java Beans Clashing" New topic
Author

Tomcat Compiled Java Beans Clashing

Soo Yeong Kim
Greenhorn

Joined: Nov 06, 2009
Posts: 1
Hi,

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?


Thanks
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
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?

Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat Compiled Java Beans Clashing
 
Similar Threads
How to pass Session object between two web apps
WebApps not isolated in Tomcat?
JSP can't find bean classes
How to get another webapp's jndi object from local?
Apache Tomcat/4.0.6 - HTTP Status 500 - Internal Server Error