• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Tomcat Compiled Java Beans Clashing

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67503
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic