• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat Compiled Java Beans Clashing

 
Soo Yeong Kim
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If they are not identical classes, they should not have the same package and class names. That's a recipe for disaster.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic