-
1. Re: Sharing a class between 2 ears (classloader)
peterj Jun 2, 2008 6:26 PM (in response to quaidbrown)You should not have to do anything. The classes in both ears are loaded using the same class loader repository, so each ear should have access to the classes in the other ear. Only if you don't want this to happen do you have to do extra work.
Note that for classes in a war it is exactly the opposite - you cannot use classes in a war file from external to that war. -
2. Re: Sharing a class between 2 ears (classloader)
quaidbrown Jun 2, 2008 6:49 PM (in response to quaidbrown)Well, I was getting noclassdeffound errors. The problem was that the the jboss-app for the 2 ears had a different entry in the <jboss-app><loader-repository></loader-repository></jboss-app> tag.
By making those 2 entries identical, the classes loaded from the original ear were available to the other ear.
Now, the problem I'm facing is that the Entity bean I wanted to share is persisting to Ear1's defined datasource instead of Ear2's datasource. I imagine this is because when jboss starts up, it does some maping for entity beans so it can quickly write to the DB.
I'm not sure if I am going to be able to find a way to make it treat the Entity bean differently depending on which application is calling it. I may have to write some persistence code in Ear2 to make sure that it is writing the way I want it to, instead of just using EntityManager's persist method. -
3. Re: Sharing a class between 2 ears (classloader)
peterj Jun 3, 2008 11:02 AM (in response to quaidbrown)Ah, you defined a loader repository. That is what I meant by "Only if you don't want this to happen do you have to do extra work."
-
4. Re: Sharing a class between 2 ears (classloader)
quaidbrown Jun 3, 2008 11:50 AM (in response to quaidbrown)Ya, I guess that the wizard that generated my project did some extra work for me without telling me :)
Because the 2 projects had their own loader repository, it wasn't really automatic.
That said, this solution isn't really 100% what I was hoping for. Now I have to worry about these 2 projects defining objects with the same name... since they have the same class loader and name, they will conflict, yes?
I am really only interested in a specific package of the other ear. Any guesses on how to only share some parts of an ear and retain independent namespaces for the rest? -
5. Re: Sharing a class between 2 ears (classloader)
peterj Jun 3, 2008 1:01 PM (in response to quaidbrown)On sharing a jar, a couple of possibilities:
1) Put that jar in server/xxx/lib (not ideal, but doable)
2) Create a third ear without a classloader repository, and put the jar into that ear. (This is the solution I have used before.)