Hi Fernando,

thanks for the review. The problem is related to loading and I think you
got the point, in fact I had the same interface for multiple implementation.

However, even changing this I had some stranger issues related to the fact
that it was not possible (due to classloading problems) to have EJBs in
both the WAR and the jar inside the EAR.

I have solved by going through a code refactor and eliminating the
inconsistent design. Now there is no more need of having ejbs in the war
and the whole design of the application is more JEE compliant so it should
work more easily on different AS.

On Thu, Sep 6, 2012 at 4:55 PM, Fernando Lozano <[email protected]>wrote:

> Hi,
>
> I haven't been following this thread since the start, but from the quotes
> on the lastest message I wonder wether you have a classloader problem. Have
> you already considered this?
>
> Hope this long explanation is intelligible and helps. If not, please
> forgive my intromission and my poor english.
>
> This is very common for developers moving from JBoss to another app
> server, because the default config for JBoss (before 7.x) was the "unified
> classloader" (UC), where each deployment could see classes from other
> deployments. But the Java EE specs state that each deployment (and each
> subdeployment, i.e. package inside the same EAR) gets it own classloader
> and won't be able to see classes from other deployments or subdeployments.
>
> See the error you got was a class loading exception:
>
>
> JBException: Error while loading bean class 
> org.test.galaxy.**WarBroadcasterBean
> for bean WarBroadcasterBean.
> Received message: Cannot locate the class org.test.galaxy.**WarBroadcasterBean
> from the codebase
> [/home/luca/bin/apache-tomee-**snapshot/apps/Test.ear/pn-**galaxy]:
>
> Class WarBroadcasterBean is one of the implementations of interface
> BroadcasterBeanLocal, i.e., one of the EJBs that implements the same
> interface, am I right? It looks like either one of the subdeployments tried
> to load the implementation class for the EJB (they shouln't) or the
> implementation class itself has a dependency on some other class/interface
> that is not on it's own subdeployment classloader.
>
> Usually, classes that are need for more than one subdeployment are
> packaged in a library JAR inside the EAR, vich becomes visible by all other
> subdeployment classloaders, and no other subdeployment includes the same
> class definitions. But JBoss developers are used to either copy the same
> classes to many subdeployments -- jboss UC will load the first definition
> found and ignore the others -- or having just one definition in the
> implementation package for the EJBs, and other subdeployments see them
> because of the UC. But both are packagings that violate the Java EE specs.
>
> Maybe if you review the packaging structure x classloaders and ejb names
> you'll find something inconsistent.
>
>
> []s, Fernando Lozano
>
>
>  Yes, but even a plain EJB inside the war without any reference to other
>> EJB
>> will fail.
>>
>> I solved by implementing JMS client on the WAR application, so the ejb and
>> the war communicate through a queue.
>> Not the best, but at least it should be more consistent and portable among
>> different Application Servers.
>>
>> On Thu, Sep 6, 2012 at 12:18 PM, Romain Manni-Bucau
>> <[email protected]>wrote:
>>
>>  Same reason i guess, you use cross ejb in your mdb?
>>> Le 6 sept. 2012 11:47, "Luca Merolla" <[email protected]> a écrit :
>>>
>>>  I have tried to place an MDB in the WAR... It still fails in the same
>>>> way
>>>> as for the Stateless bean.
>>>>
>>>> On Thu, Sep 6, 2012 at 8:04 AM, Romain Manni-Bucau <
>>>>
>>> [email protected]
>>>
>>>> wrote:
>>>>> It is but it leads to the kind of deployment lifecycle you have (and
>>>>>
>>>> from a
>>>>
>>>>> spec point of view not sure it is well defined)
>>>>> Le 6 sept. 2012 00:17, "Luca Merolla" <[email protected]> a
>>>>>
>>>> écrit :
>>>
>>>> I have been investigating on this issue. The fact is failing not to
>>>>>>
>>>>> lookup
>>>>>
>>>>>> for the EJB that is inside the WAR, but it is failing while building
>>>>>>
>>>>> it.
>>>>
>>>>> If I do remove @Stateless and the interface implementation from the
>>>>>> WarBroadcasterBean it deploys fine and I guess WarBroadcaster is
>>>>>>
>>>>> considered
>>>>>
>>>>>> a CDI bean.
>>>>>> But in this case I'm not able to retrieve it by lookup...
>>>>>>
>>>>>> It is not possible to have EJBs both inside a WAR and into a library
>>>>>>
>>>>> in
>>>
>>>> the
>>>>>
>>>>>> same EAR?
>>>>>>
>>>>>> On Mon, Sep 3, 2012 at 6:44 PM, Romain Manni-Bucau <
>>>>>>
>>>>> [email protected]
>>>>>
>>>>>> wrote:
>>>>>>> Hmm maybe i got it wrong but in an ear you can share ejb for
>>>>>>>
>>>>>> webapps
>>>
>>>> so
>>>>
>>>>> putting all ejb in  ejbmodules of the ear instead of war will make
>>>>>>>
>>>>>> it
>>>
>>>>  consistent
>>>>>>> Le 3 sept. 2012 18:29, "Luca Merolla" <[email protected]> a
>>>>>>>
>>>>>> écrit :
>>>>>
>>>>>> They are inside an EAR folder. Would it make any difference if I
>>>>>>>>
>>>>>>> do a
>>>>
>>>>>  packaged EAR?
>>>>>>>>
>>>>>>>> On Mon, Sep 3, 2012 at 3:33 PM, Romain Manni-Bucau <
>>>>>>>>
>>>>>>> [email protected]
>>>>>>>
>>>>>>>> wrote:
>>>>>>>>> Hmm, either managing this case or packaging an ear should solve
>>>>>>>>>
>>>>>>>> it
>>>>
>>>>> IMO
>>>>>>
>>>>>>> Le 3 sept. 2012 14:18, "Luca Merolla" <[email protected]>
>>>>>>>>>
>>>>>>>> a
>>>
>>>>  écrit :
>>>>>>>
>>>>>>>> I changed a bit the code and I gave a try with @EJB and I get
>>>>>>>>>>
>>>>>>>>> the
>>>>
>>>>> same
>>>>>>>
>>>>>>>> exception.
>>>>>>>>>>
>>>>>>>>>> The reason why there was JNDI lookups is because we are
>>>>>>>>>>
>>>>>>>>> calling
>>>
>>>>  actually
>>>>>>>>
>>>>>>>>> 2
>>>>>>>>>
>>>>>>>>>> ejbs in 2 different wars that implements the same interface
>>>>>>>>>>
>>>>>>>>>> private BroadcasterBeanLocal warBroadcaster;
>>>>>>>>>> private BroadcasterBeanLocal war2Broadcaster;
>>>>>>>>>>
>>>>>>>>>> probably that can be solved with @EJB(name="") or something
>>>>>>>>>>
>>>>>>>>> similar.
>>>>>>
>>>>>>>  However, I think the problem is related to the order of
>>>>>>>>>>
>>>>>>>>> deployment.
>>>>>
>>>>>>  Basically when the EJB application (jar) is deployed, it
>>>>>>>>>>
>>>>>>>>> starts
>>>
>>>> with
>>>>>>
>>>>>>> Quartz
>>>>>>>>>
>>>>>>>>>> for the timers, but at that time the WAR application hasn't
>>>>>>>>>>
>>>>>>>>> been
>>>>
>>>>>  deployed
>>>>>>>>
>>>>>>>>> yet so the warBroadcaster beans are not available and the
>>>>>>>>>>
>>>>>>>>> deployment
>>>>>>
>>>>>>> fails
>>>>>>>>>
>>>>>>>>>> with:
>>>>>>>>>>
>>>>>>>>>> SEVERE: Application could not be deployed:
>>>>>>>>>>   /home/luca/bin/apache-tomee-**snapshot/apps/Test.ear
>>>>>>>>>> org.apache.openejb.**OpenEJBException: Creating application
>>>>>>>>>>
>>>>>>>>> failed:
>>>>
>>>>>  /home/luca/bin/apache-tomee-**snapshot/apps/Test.ear: Error
>>>>>>>>>>
>>>>>>>>> building
>>>>>
>>>>>> bean
>>>>>>>
>>>>>>>> 'WarBroadcasterBean'.  Exception: class
>>>>>>>>>>
>>>>>>>>> org.apache.openejb.OpenE
>>>>
>>>>>  JBException: Error while loading bean class
>>>>>>>>>> org.test.galaxy.**WarBroadcasterBean for bean
>>>>>>>>>>
>>>>>>>>> WarBroadcasterBean.
>>>
>>>>  Received
>>>>>>>>
>>>>>>>>> message: Cannot locate the class
>>>>>>>>>>
>>>>>>>>> org.test.galaxy.**WarBroadcasterBean
>>>>>
>>>>>> from
>>>>>>>>
>>>>>>>>>   the codebase
>>>>>>>>>>
>>>>>>>>>>  [/home/luca/bin/apache-tomee-**snapshot/apps/Test.ear/pn-**
>>> galaxy]:
>>>
>>>> Error
>>>>>>
>>>>>>> while
>>>>>>>>>
>>>>>>>>>> loading bean class org.test.galaxy.**WarBroadcasterBean for
>>>>>>>>>>
>>>>>>>>> bean
>>>
>>>>  WarBroadcasterBean. Received message: C
>>>>>>>>>> annot locate the class org.test.galaxy.**WarBroadcasterBean
>>>>>>>>>>
>>>>>>>>> from
>>>
>>>> the
>>>>>
>>>>>>  codebase
>>>>>>>>>
>>>>>>>> [/home/luca/bin/apache-tomee-**snapshot/apps/Test.ear/pn-**galaxy]
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.openejb.assembler.**classic.Assembler.**
>>> createApplication(Assembler.**java:929)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.openejb.assembler.**classic.Assembler.**
>>> createApplication(Assembler.**java:521)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.openejb.assembler.**classic.Assembler.**
>>> buildContainerSystem(**Assembler.java:422)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>  org.apache.openejb.assembler.**classic.Assembler.build(**
>>>> Assembler.java:330)
>>>>
>>>>>           at
>>>>>>>>>>
>>>>>>>>> org.apache.openejb.OpenEJB$**Instance.<init>(OpenEJB.java:**144)
>>>>>>>
>>>>>>>>          at org.apache.openejb.OpenEJB.**init(OpenEJB.java:290)
>>>>>>>>>>          at
>>>>>>>>>>
>>>>>>>>>>  org.apache.tomee.catalina.**TomcatLoader.initialize(**
>>>> TomcatLoader.java:231)
>>>>
>>>>>           at
>>>>>>>>>>
>>>>>>>>>>  org.apache.tomee.catalina.**TomcatLoader.init(**
>>>>> TomcatLoader.java:131)
>>>>>
>>>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.tomee.catalina.**ServerListener.lifecycleEvent(**
>>> ServerListener.java:113)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.catalina.util.**LifecycleSupport.**
>>> fireLifecycleEvent(**LifecycleSupport.java:119)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.catalina.util.**LifecycleBase.**fireLifecycleEvent(**
>>> LifecycleBase.java:90)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.catalina.util.**LifecycleBase.**setStateInternal(**
>>> LifecycleBase.java:401)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>  org.apache.catalina.util.**LifecycleBase.init(**
>>>>> LifecycleBase.java:110)
>>>>>
>>>>>>           at
>>>>>>>>>>
>>>>>>>>> org.apache.catalina.startup.**Catalina.load(Catalina.java:**624)
>>>>>>>
>>>>>>>>          at
>>>>>>>>>>
>>>>>>>>> org.apache.catalina.startup.**Catalina.load(Catalina.java:**649)
>>>>>>>
>>>>>>>>          at
>>>>>>>>>>
>>>>>>>>> sun.reflect.**NativeMethodAccessorImpl.**invoke0(Native
>>>
>>>>  Method)
>>>>>>>
>>>>>>>>          at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  sun.reflect.**NativeMethodAccessorImpl.**invoke(**
>>> NativeMethodAccessorImpl.java:**39)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  sun.reflect.**DelegatingMethodAccessorImpl.**invoke(**
>>> DelegatingMethodAccessorImpl.**java:25)
>>>
>>>>           at java.lang.reflect.Method.**invoke(Method.java:597)
>>>>>>>>>>          at
>>>>>>>>>>
>>>>>>>>> org.apache.catalina.startup.**Bootstrap.load(Bootstrap.java:**281)
>>>>>>>>
>>>>>>>>>          at
>>>>>>>>>>
>>>>>>>>> org.apache.catalina.startup.**Bootstrap.main(Bootstrap.java:**450)
>>>>>>>>
>>>>>>>>> Caused by: org.apache.openejb.**OpenEJBException: Error
>>>>>>>>>>
>>>>>>>>> building
>>>
>>>> bean
>>>>>
>>>>>>  'WarBroadcasterBean'.  Exception: class
>>>>>>>>>> org.apache.openejb.**OpenEJBException: Error while loading bean
>>>>>>>>>>
>>>>>>>>> class
>>>>>
>>>>>>  org.test.galaxy.**WarBroadcasterBean for bean
>>>>>>>>>>
>>>>>>>>> WarBroadcasterBean.
>>>
>>>>  Received
>>>>>>>>
>>>>>>>>> message: Cannot locate the class
>>>>>>>>>>
>>>>>>>>> org.test.galaxy.**WarBroadcasterBean
>>>>>
>>>>>> from
>>>>>>>>
>>>>>>>>> the codebase
>>>>>>>>>>
>>>>>>>>>>  [/home/luca/bin/apache-tomee-**snapshot/apps/Test.ear/pn-**
>>> galaxy]:
>>>
>>>> Error
>>>>>>
>>>>>>> while
>>>>>>>>>
>>>>>>>>>> loading bean class org.test.galaxy.**WarBroadcasterBean for
>>>>>>>>>>
>>>>>>>>> bean
>>>
>>>>  WarBroadcasterBean. Received message: Cannot locate the class
>>>>>>>>>> org.test.galaxy.**WarBroadcasterBean from the codebase
>>>>>>>>>>
>>>>>>>>>>  [/home/luca/bin/apache-tomee-**snapshot/apps/Test.ear/pn-**
>>> galaxy]
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.openejb.assembler.**classic.EjbJarBuilder.build(**
>>> EjbJarBuilder.java:81)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.openejb.assembler.**classic.Assembler.**
>>> createApplication(Assembler.**java:689)
>>>
>>>>           ... 20 more
>>>>>>>>>> Caused by: org.apache.openejb.**OpenEJBException: Error while
>>>>>>>>>>
>>>>>>>>> loading
>>>>>
>>>>>> bean
>>>>>>>>
>>>>>>>>> class org.test.galaxy.**WarBroadcasterBean for bean
>>>>>>>>>>
>>>>>>>>> WarBroadcasterBean.
>>>>>>
>>>>>>>  Received message: Cannot locate the class
>>>>>>>>>> org.test.galaxy.**WarBroadcasterBean from the codebase
>>>>>>>>>>
>>>>>>>>>>  [/home/luca/bin/apache-tomee-**snapshot/apps/Test.ear/pn-**
>>> galaxy]
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.openejb.assembler.**classic.EnterpriseBeanBuilder.**
>>> load(EnterpriseBeanBuilder.**java:428)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.openejb.assembler.**classic.EnterpriseBeanBuilder.**
>>> loadClass(**EnterpriseBeanBuilder.java:**405)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.openejb.assembler.**classic.EnterpriseBeanBuilder.**
>>> build(EnterpriseBeanBuilder.**java:81)
>>>
>>>>           at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  org.apache.openejb.assembler.**classic.EjbJarBuilder.build(**
>>> EjbJarBuilder.java:66)
>>>
>>>>           ... 21 more
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Mon, Sep 3, 2012 at 1:47 PM, Thiago Veronezi <
>>>>>>>>>>
>>>>>>>>> [email protected]
>>>>>>
>>>>>>>  wrote:
>>>>>>>>>>
>>>>>>>>>>  You could remove the init method altogether and simple
>>>>>>>>>>>
>>>>>>>>>> inject
>>>
>>>> the
>>>>>
>>>>>> bean
>>>>>>>>
>>>>>>>>> in
>>>>>>>>>
>>>>>>>>>> your object...
>>>>>>>>>>>
>>>>>>>>>>> @EJB
>>>>>>>>>>> private WarBroadcaster warBroadcaster;
>>>>>>>>>>>
>>>>>>>>>>> This way you avoid JNDI lookups.
>>>>>>>>>>>
>>>>>>>>>>> []s,
>>>>>>>>>>> Thiago.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Sep 3, 2012 at 7:10 AM, Luca Merolla <
>>>>>>>>>>>
>>>>>>>>>> [email protected]
>>>>>>>
>>>>>>>>  wrote:
>>>>>>>>>>>
>>>>>>>>>>>  Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> I have a piece of code that I would like to port from
>>>>>>>>>>>>
>>>>>>>>>>> JBoss
>>>
>>>> to
>>>>>
>>>>>> TomEE.
>>>>>>>>
>>>>>>>>>  The old code, which was working on JBoss, is like that.
>>>>>>>>>>>>
>>>>>>>>>>> Inside
>>>>>
>>>>>> the
>>>>>>>
>>>>>>>> same
>>>>>>>>>
>>>>>>>>>> EAR
>>>>>>>>>>>
>>>>>>>>>>>> folder I have:
>>>>>>>>>>>>
>>>>>>>>>>>> - EJB jar (with EJBs and timers)
>>>>>>>>>>>> - WAR (web application, with 1 EJB)
>>>>>>>>>>>>
>>>>>>>>>>>> I have a requirement that the ejb timers (a method
>>>>>>>>>>>>
>>>>>>>>>>> annotated
>>>>
>>>>> with
>>>>>>
>>>>>>>  @Schedule)
>>>>>>>>>>>> will perform a task every X seconds.
>>>>>>>>>>>> This method calls an EJB (inside the jar) that will call
>>>>>>>>>>>>
>>>>>>>>>>> another
>>>>>>
>>>>>>> EJB,
>>>>>>>>
>>>>>>>>> but
>>>>>>>>>>
>>>>>>>>>>> this time in a WAR application.
>>>>>>>>>>>>
>>>>>>>>>>>> Basically the EJB in the jar has something like that:
>>>>>>>>>>>>
>>>>>>>>>>>> @PostConstruct
>>>>>>>>>>>> public void init() {
>>>>>>>>>>>> log.info("INIT-BROADCASTERS");
>>>>>>>>>>>> try {
>>>>>>>>>>>>   warBroadcaster = (BroadcasterBeanLocal) initialContext
>>>>>>>>>>>> .lookup("java:app/pn-test/**WarBroadcasterBean");
>>>>>>>>>>>> } catch (NamingException e) {
>>>>>>>>>>>> log.error("Problem looking up for broadcasters", e);
>>>>>>>>>>>> }
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> This approach seems to not work on TomEE. I have tried to
>>>>>>>>>>>>
>>>>>>>>>>> add:
>>>>>
>>>>>>  Properties p = new Properties();
>>>>>>>>>>>> p.put(Context.INITIAL_CONTEXT_**FACTORY,
>>>>>>>>>>>> "org.apache.openejb.client.**LocalInitialContextFactory");
>>>>>>>>>>>> final InitialContext initialContext = new
>>>>>>>>>>>>
>>>>>>>>>>> InitialContext(p);
>>>>
>>>>>  But still it can't find the bean. I don't know if it's
>>>>>>>>>>>>
>>>>>>>>>>> possible
>>>>>
>>>>>> to
>>>>>>>
>>>>>>>> do
>>>>>>>>
>>>>>>>>>  something like that but anyway if you have any
>>>>>>>>>>>>
>>>>>>>>>>> suggestions
>>>
>>>> or
>>>>
>>>>>  different
>>>>>>>>>
>>>>>>>>>> approach I would be very keen to refactor this code to
>>>>>>>>>>>>
>>>>>>>>>>> make
>>>
>>>> it
>>>>>
>>>>>> work
>>>>>>>
>>>>>>>>  properly on TomEE.
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks in advance,
>>>>>>>>>>>> Luca
>>>>>>>>>>>>
>>>>>>>>>>>
>

Reply via email to