Skip to main content

Problem with accessing EJB Components in a Remote GlassFish Server

4 replies [Last post]
Joined: 2014-01-22
Points: 0


i've got 2 GF 4 ....

on one(Service-GF) is the EJB deployed as an EAR Package!

And on the other one (Client-GF) we deployed an WAR Package.

The goal is to get access from the Client-GF (Business Activity Classes) to the Remote (Business Activity Classes) on the Service-GF.

Service-GF Interface Code:

public interface IBackendConfigurationBA {

public void createConfig(ConfigurationModel configurationModel);


Service-GF Bean Code:

@Singleton(name="BackendConfigurationBA", mappedName="BackendConfigurationBA")
public class BackendConfigurationBA implements IBackendConfigurationBA {

private final Logger logger = LoggerFactory.getLogger(CirrusConfig.class);

private CirrusConfig cirrusConfig = CirrusConfig.getInstance();

private BackendConfigurationMapper configurationMapper = new BackendConfigurationMapper();

@EJB(beanName = "BackendConfigurationDAO")
private IBackendConfigurationDAO backendConfigDAO;


Client-GF Interface Code:

public interface IFrontendConfigurationBA {

public void reloadConfigs();


Client-GF Bean Code:

public class FrontendConfigurationBA implements IFrontendConfigurationBA{

private final Logger logger = LoggerFactory.getLogger(CirrusConfig.class);

@EJB(name ="BackendConfigurationBA")
private IBackendConfigurationBA backendConfigurationBA;


What strategy should I use in order to connect both with each other.

I read here:

The ejb-ref element in glassfish-web.xml looks like this:


in my case...i did this:


But this doesn't help. I get the Error:

[2014-01-22T13:54:22.516+0100] [glassfish 4.0] [SEVERE] [] [global] [tid: _ThreadID=37 _ThreadName=admin-listener(3)] [timeMillis: 1390395262516] [levelValue: 1000] [[
Class [ Lde/br/wtr/be/activity/configuration/IBackendConfigurationBA; ] not found. Error while loading [ class ]]]


[2014-01-22T13:54:22.657+0100] [glassfish 4.0] [SEVERE] [NCLS-CORE-00026] [javax.enterprise.system.core] [tid: _ThreadID=37 _ThreadName=admin-listener(3)] [timeMillis: 1390395262657] [levelValue: 1000] [[
Exception during lifecycle processing
java.lang.IllegalArgumentException: Invalid ejb jar wtr-web-0.0.1-SNAPSHOT: it contains zero ejb. A valid ejb jar requires at least one session/entity/message driven bean.
at org.glassfish.ejb.deployment.util.EjbBundleValidator.accept(
at org.glassfish.ejb.deployment.util.EjbBundleValidator.accept(
at com.sun.enterprise.deployment.BundleDescriptor.visit(
at org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl.visit(
at com.sun.enterprise.deployment.util.ApplicationValidator.accept(
at com.sun.enterprise.deployment.BundleDescriptor.visit(
at com.sun.enterprise.deployment.archivist.ApplicationFactory.openArchive(
at org.glassfish.javaee.core.deployment.DolProvider.processDOL(
at org.glassfish.javaee.core.deployment.DolProvider.load(
at org.glassfish.javaee.core.deployment.DolProvider.load(
at com.sun.enterprise.v3.server.ApplicationLifecycle.loadDeployer(
at com.sun.enterprise.v3.server.ApplicationLifecycle.setupContainerInfos(
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(
at org.glassfish.deployment.admin.DeployCommand.execute(
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$
at Method)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(
at org.glassfish.grizzly.http.server.StaticHttpHandler.service(
at org.glassfish.grizzly.http.server.HttpHandler.runService(
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(
at org.glassfish.grizzly.ProcessorExecutor.execute(
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(
at org.glassfish.grizzly.threadpool.AbstractThreadPool$

[2014-01-22T13:54:22.664+0100] [glassfish 4.0] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=37 _ThreadName=admin-listener(3)] [timeMillis: 1390395262664] [levelValue: 1000] [[
Exception while deploying the app [wtr-web-0.0.1-SNAPSHOT] : Invalid ejb jar wtr-web-0.0.1-SNAPSHOT: it contains zero ejb. A valid ejb jar requires at least one session/entity/message driven bean.]]

Thank you in advance


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2014-01-22
Points: 0

Hello again :)

no one an idea? Sorry, probably too much text.

It would really help, if somone has or know an example how to access a EJB that is packed in a EAR file from an WAR with 2 !seperate! Glashfish 4 servers (javaee7).

Its really exhausting to find something useful in the web. Where i have to register the access? the ejb-jar.xml or glassfish-ejb-jar.xml or in the admin console of the Glassfish or in the glassfish-web.xml ...and so on....

And how ... there a so many variants how to reference an remote EJB ?


I need to adjust something in the server (admin console)? Or can i put the settings in the admin console of the server an refer the access over a different way?

There are sooooooo much possible locations : ( I would bet, a lot of users are confused about this topic.

Thank you in advance for your time!

A goodie .... that ive found somewhere in the web... LOL:

>> Quote: "I solved my problem, I migrate to JBoss 7.1.1, read the tutorial and in my first test all worked fine, in the way that I desired but using JBoss instead Glassfish."

Joined: 2013-10-23
Points: 0

Dear Grauzone,

to access an EJB from remote you have the points below

1. Make sure your EJB is set as @Remote EJB, so the ejb can be accessed from different JVM.
You can use @Local when client and EJB is in the same JVM

for example

public interface CustomerBeanRemote {

//your code here

2. Implements the interface into the EJB class, in this case i'am use Singleton EJB
you can also use the same thing for stateless and statefull.

@Singleton(name="CustomerBeanRemote", mappedName="CustomerBeanRemote), description="CustomerBeanRemote")
public class CustomerBean implements CustomerBeanRemote {
//your code here

3. To accessing your EJB then create some synchronize method and add this properties to be used for each time you create initialcontext object

Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state", "");

// optional. Defaults to localhost. Only needed if web server is running
// on a different host than the appserver
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");

// optional. Defaults to 3700. Only needed if target orb port is not 3700.
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

InitialContext ic = new InitialContext(props);
CustomerBeanRemote cbr = (CustomerBeanRemote)ic.lookup("CustomerBean");

4. Glassfish has been provide some client container called ACC --> Application client provider
When you create an EJB client application. then the configuration in point 3 is no need to create manually.
Glassfish will create it for you.

Hope this answer will help you to solve the problem.
Just give me some feedback if you have some problem.


Joined: 2014-01-22
Points: 0

Hey Ferry,

thanks a lot for your replay!!!

I made Points 1. and 2. this is clear.

But Points 3. and 4. are my Problems.

1. The Ejb (EAR File) is NOT on the same maschine as my Webapplication (WAR File). I think i must add the properties to my Webapplication, because how could my WAR know where to find the remote ejb

2. Then i have another Problem.
Can I access the EJBwith the annotation @EJB?
Is this Initial Context bla in this case necessary? Don't get me wrong, but if you have this annotation already, then I have a feeling that this procedure (Initial Context) is in some cases perhaps very laborious.
I thought, that Java will make some voodoo (concerning on the annotation) and lookup for my Remote EJB, assuming I've set the correct properties.

3. An once another question.
Can I set the properties in the admin backend of the Glassfish (http://localhost:4848). I found the topic:
Configurations > server-config > ORB > IIOP Listeners
Is this the right place to refere the remote maschine and do I have something to consider?

Thanks a lot (and for your time!)

Joined: 2013-10-23
Points: 0

Hi Vladimir,

1. yes, i agreed with you

2. Off course, you can use @EJB to access an EJB but you need to define @LocalBean in the session bean class and
this annotation only can be used for accesing local EJB. Please refer to EJB 3.1 for further information.

Commonly initialContext properties will need to be define, if you want to access an EJB from remote/another server.
You can try this properties as in my replied email before (point 3).
I usually use this way rather than use container configuration.

you can refer to this answer :

3. Yes, that configuration is used to configure IIOP port listener that your remote server will listen for IIOP Request. default 3700

Hope this will help you