Skip to main content

Accessing an EJB in an ear from a war

8 replies [Last post]
chris1234
Offline
Joined: 2012-11-06
Points: 0

Hi everyone,

we have the following scenario, please bear with the lengthy explanation!

We are running Glassfish 3.1.2 and we do development in Netbeans. We have TestEar.ear containing TestWeb.war and TestEjb.jar which contains some stateless session beans. Then we have VirtualWeb.war which we deploy to the same Glassfish instance but a separate virtual server. VirtualWeb.war needs to access the EJBs in TestEjb.jar (in the ear).

We add TestEjb.jar to the libraries of VirtualWeb.war so that it can compile.

From within VirtualWeb.war, we try to lookup a reference to an EJB (say Ejb1) using the JNDI name "java:global/TestEar/TestEjb/Ejb1", however this fails. If we instead lookup "java:global/VirtualWeb/Ejb1", this works.

This means that separate EJB components are created when deploying VirtualWeb.war.
How can this be prevented? All we want to do is access the already deployed EJBs in TestEar.ear.

Any help would be appreciated!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04
Points: 0

To look up a remote EJB, it must have a remote interface exposed. Include that remote interface into your VirtualWeb.war.

chris1234
Offline
Joined: 2012-11-06
Points: 0

Hi, thank you for the response mvatkina!

So does that mean local EJB access is only possible within an ear? I cannot have local access in our scenario described above (from VirtualWeb.war to an EJB in TestEar.ear)? It's the same Glassfish instance, same JVM...

pljosh
Offline
Joined: 2006-12-05
Points: 0

Yes, you have to package everything into same ear or separate remote
interfaces and bundle them with other applications, so they can access
remote beans. The fact that this is all single JVM does not matter.

Regards,
Witold Szczerba
---
Sent from my mobile phone.
On Dec 28, 2012 3:18 PM, wrote:

> Hi, thank you for the response mvatkina! So does that mean local EJB access
> is only possible within an ear? I cannot have local access in our scenario
> described above (from VirtualWeb.war to an EJB in TestEar.ear)? It's the
> same
> Glassfish instance, same JVM...
>
> --
>
> [Message sent by forum member 'chris1234']
>
> View Post: http://forums.java.net/node/**893478
>
>
>

mgainty
Offline
Joined: 2004-05-21
Points: 0

Wittold at the bank we built our ears with an OSGI build

would this help the op insofar as to specifically export-packages of the package names of the beans the op wants to access remotelyThis would have the additional benefit of placing the export-package declaration in the manifest?http://wso2.org/library/tutorials/develop-osgi-bundles-using-maven-bundle-plugin#Exporting%20packages
http://fusesource.com/docs/esb/4.4/esb_deploy_osgi/BestPractices-BuildBu...

Dzięki

Dzieki
Martin
______________________________________________

Nie zmienia ani nie zakłóca tego przekazuNie zmienia ani nie zakłóca tego przekazu

Date: Sat, 29 Dec 2012 12:28:59 +0100
Subject: Re: Accessing an EJB in an ear from a war
From: pljosh.mail@gmail.com
To: users@glassfish.java.net

Yes, you have to package everything into same ear or separate remote interfaces and bundle them with other applications, so they can access remote beans. The fact that this is all single JVM does not matter.
Regards,

Witold Szczerba

---

Sent from my mobile phone.
On Dec 28, 2012 3:18 PM, wrote:

Hi, thank you for the response mvatkina! So does that mean local EJB access

is only possible within an ear? I cannot have local access in our scenario

described above (from VirtualWeb.war to an EJB in TestEar.ear)? It's the same

Glassfish instance, same JVM...

--

[Message sent by forum member 'chris1234']

View Post: http://forums.java.net/node/893478

pljosh
Offline
Joined: 2006-12-05
Points: 0

I don't know how OSGI works on Glassfish when deploying EARs, but as far as
I know, in general, each application, be it WAR or EAR has it's own root
classloader, so it is not possible to invoke session beans of one
application from within another. How should that work? Maybe some Glassfish
specific techniques applies here like one more parent classloader shared
between all applications working as a kind of bridge? I don't know.

Regards,
Witold Szczerba

On 30 December 2012 00:56, Martin Gainty wrote:

> Wittold
>
> at the bank we built our ears with an OSGI build
>
> would this help the op insofar as to specifically export-packages of the
> package names of the beans the op wants to access remotely
> This would have the additional benefit of placing the export-package
> declaration in the manifest
> ?
>
> http://wso2.org/library/tutorials/develop-osgi-bundles-using-maven-bundl...
>
> http://fusesource.com/docs/esb/4.4/esb_deploy_osgi/BestPractices-BuildBu...
> Dzięki
>
>
> Dzieki
> Martin
>
> ______________________________________________
>
> Nie zmienia ani nie zakłóca tego przekazu
> Nie zmienia ani nie zakłóca tego przekazu
>

mgainty
Offline
Joined: 2004-05-21
Points: 0

Szczerba raises a good point.
the short answer is "depends on the classloader prioritisation of the AppServer" i think we're safe as long as we implement the Glassfish 'Archive' Classloader http://docs.oracle.com/cd/E18930_01/html/821-2418/beadf.html
The Archive class loader loads classes from the WAR, EAR, and
JAR files or directories (for directory deployment) of applications or modules
deployed to the GlassFish Server. This class loader also loads any
application-specific classes generated by the GlassFish Server runtime, such as
stub classes or servlets generated by JSP pages.
Dzięki
Martin
______________________________________________
Proszę nie zmieniać lub zakłócić tego przekazu Date: Sun, 30 Dec 2012 02:16:54 +0100
Subject: Re: Accessing an EJB in an ear from a war
From: pljosh.mail@gmail.com
To: users@glassfish.java.net

I don't know how OSGI works on Glassfish when deploying EARs, but as far as I know, in general, each application, be it WAR or EAR has it's own root classloader, so it is not possible to invoke session beans of one application from within another. How should that work? Maybe some Glassfish specific techniques applies here like one more parent classloader shared between all applications working as a kind of bridge? I don't know.

Regards,
Witold Szczerba

On 30 December 2012 00:56, Martin Gainty wrote:

Wittold

at the bank we built our ears with an OSGI build

would this help the op insofar as to specifically export-packages of the package names of the beans the op wants to access remotely
This would have the additional benefit of placing the export-package declaration in the manifest

?
http://wso2.org/library/tutorials/develop-osgi-bundles-using-maven-bundl...

http://fusesource.com/docs/esb/4.4/esb_deploy_osgi/BestPractices-BuildBu...

Dzięki

Dzieki
Martin

______________________________________________

Nie zmienia ani nie zakłóca tego przekazuNie zmienia ani nie zakłóca tego przekazu

Date: Sat, 29 Dec 2012 12:28:59 +0100
Subject: Re: Accessing an EJB in an ear from a war
From: pljosh.mail@gmail.com
To: users@glassfish.java.net

Yes, you have to package everything into same ear or separate remote interfaces and bundle them with other applications, so they can access remote beans. The fact that this is all single JVM does not matter.

Regards,

Witold Szczerba

---

Sent from my mobile phone.

On Dec 28, 2012 3:18 PM, wrote:

Hi, thank you for the response mvatkina! So does that mean local EJB access

is only possible within an ear? I cannot have local access in our scenario

described above (from VirtualWeb.war to an EJB in TestEar.ear)? It's the same

Glassfish instance, same JVM...

--

[Message sent by forum member 'chris1234']

View Post: http://forums.java.net/node/893478

mvatkina
Offline
Joined: 2005-04-04
Points: 0

Local EJB access is available only within a ear per the EJB spec. Some vendors do provide local access between applications, but it's not a portable behavior, and is not available in GlassFish.

HTH,
-marina

mgainty
Offline
Joined: 2004-05-21
Points: 0

java:global[/application name]/module name/enterprise bean name[/interface name]
Application name and module name default to the name of the application and
module minus the file extension.
Application names are required only if the
application is packaged within an EAR. The interface name is required only if
the enterprise bean implements more than one business interface.
java:global/VirtualWeb/Ejb1

Ejb1 is not packaged within an application so application-name identifier is un-necessary
There is not more than one business interface so interface-name identifier is un-necessary
http://docs.oracle.com/javaee/6/tutorial/doc/gipjf.html Klar?
Martin
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.

> To: users@glassfish.java.net
> Subject: Accessing an EJB in an ear from a war
> From: forums@java.net
> Date: Thu, 27 Dec 2012 07:51:07 -0600
>
> Hi everyone, we have the following scenario, please bear with the lengthy
> explanation! We are running Glassfish 3.1.2 and we do development in
> Netbeans. We have TestEar.ear containing TestWeb.war and TestEjb.jar which
> contains some stateless session beans. Then we have VirtualWeb.war which we
> deploy to the same Glassfish instance but a separate virtual server.
> VirtualWeb.war needs to access the EJBs in TestEjb.jar (in the ear). We add
> TestEjb.jar to the libraries of VirtualWeb.war so that it can compile. From
> within VirtualWeb.war, we try to lookup a reference to an EJB (say Ejb1)
> using the JNDI name "java:global/TestEar/TestEjb/Ejb1", however this fails.
> If we instead lookup "java:global/VirtualWeb/Ejb1", this works. This means
> that separate EJB components are created when deploying VirtualWeb.war. How
> can this be prevented? All we want to do is access the already deployed EJBs
> in TestEar.ear. Any help would be appreciated!
>
> --
>
> [Message sent by forum member 'chris1234']
>
> View Post: http://forums.java.net/node/893478
>
>

chris1234
Offline
Joined: 2012-11-06
Points: 0

Hi Martin, thanks for the reply and pointing me in the right direction regarding JNDI naming.
However, I still don't understand why this behaviour is occurring.
I don't want the EJB to be redeployed as part of VirtualWeb.war. I only include the TestEjb.jar in the VirtualWeb.war project to get it to compile. I want the EJB to be deployed only once, as part of TestEar.ear. Then I want to access that instance of the EJB (which should be available at java:global/TestEar/TestEjb/Ejb1) from VirtualWeb.war. Is this not quite a normal way of operating? I would think this is straight forward...