2 Replies Latest reply on May 20, 2013 8:16 AM by Stephen Coy

    ClassCastException on EJB interfaces collision solution

    Vladimír Blahož Newbie

      hi,

      in our company we've got following deployment structures (very simplified) for JBoss AS 7:

       

      services.ear

      |---/lib

      |     |--- service-api.jar

      |     |--- db-service-api.jar

      |

      |--- service-impl.jar

      |--- db-service-impl.jar

       

       

      application.war

      |---/WEB-INF

      |     |--- web.xml

      |     |--- /lib

      |            |--- service-api.jar

      |            |--- db-service-api.jar

      |

      |--- other web files

       

      Service-impl and db-service-impl are EJB3 packages, with their interfaces in according api jars. Application in war calls service-impl EJBs looked up via JNDI. Service-impl EJBs than usually use db-service-impl EJBs to complete the task. The db-service-api is present in the war because sometimes it is necessary to access these services directly.

       

      Now when the ear and the war are deployed each on separated JBoss AS, everything works well. When the ear and the war archives are deployed under one JBoss 7 (for development purposes), lookup of any EJB from db-service-impl inside of any EJB from service-impl rises ClassCastException caused as far as I know by collision of interfaces placed both in ear and war (I've read lots of similar problems across the internet).

       

      One thing is that I don't really understand why is this "collision" a problem. For what I know, the class loaders for these two deployments should be completely isolated in AS7, so the deployments should behave the same way like when deployed on two JBoss instances. So I am obviously missing sth.

       

      The other thing is the solution. Now you would probably recommend to remove the EJB api archives from war and set the dependency to ear. The thing is that I need the api packages in the war, because in the production it is supposed to be able to exist without the ear deployed in the same JBoss instance. The solution we are using at the moment is the usage of different Maven profiles for compiling the war for development/production. In development profile all the EJB API archives are set to scope <provided> and jboss-deployment-structure.xml file defining the dependency on ear is added to the archive. In the production profile the jboss-deployment-structure.xml file is omitted and the API archives are set to scope <compiled>.

       

      The solution using Maven profiles works well, but it doesn't seem to me really neat. Isn't there some more elegant way to tackle this issue?

       

      Thanks for all ideas.