Skip to main content

deploy a ejb component and a web application without using EAR application

13 replies [Last post]
antoniojsg
Offline
Joined: 2007-01-04
Points: 0

Hi,

I need to know if this is possible:

1. -Deploy a EJB component to GlassFish with several session beans an entity beans
and
2.- Deploy a web application that will use the Beans previously deployed in the standalone EJB component.

I explain:
Right know I am able to ensamble a EAR application with both EJB and WAR components, everything works fine. But my EJB component will be used by several web applications, so I do not want to create severa EAR projects all using the same ejb component.

I want to deploy only one EJB component to GlassFish and then be able to deploy several WEB application that all will use the same EJB Component.

I have deployed the standalone EJB component without errors. When I try to deploy the war file of the web application I get a classNotFound exception for the interface class name . I am not able to use JNDI correctly.

Thank you for your help.

Antonio

Reply viewing options

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

Dear Sahoo,

I have finally found the problem.

As you recommended, I did change server log file level to FINE and a new error was displayed when launching the web application: a class that the EJB uses was not found when trying to inject the EJB to the JSF managed bean.

My error is that I am using an additional class library within Netbeans EJB project. This jar file is defined as a library that the EJB references. When I deploy the EJB module this jar file is not deployed in the server.

I did copy this jar file to the servers "domain1 / lib" directory, and now I am able to use the remote EJB.

Thanks a lot for your help. Your support is outstanding.

Regards,

Antonio

Sahoo

Good to know you have finally got it working...

glassfish@javadesktop.org wrote:
> Dear Sahoo,
>
> I have finally found the problem.
>
> As you recommended, I did change server log file level to FINE and a new error was displayed when launching the web application: a class that the EJB uses was not found when trying to inject the EJB to the JSF managed bean.
>
> My error is that I am using an additional class library within Netbeans EJB project. This jar file is defined as a library that the EJB references. When I deploy the EJB module this jar file is not deployed in the server.
>
> I did copy this jar file to the servers "domain1 / lib" directory, and now I am able to use the remote EJB.
>
> Thanks a lot for your help. Your support is outstanding.
>
> Regards,
>
> Antonio
> [Message sent by forum member 'antoniojsg' (antoniojsg)]
>
> http://forums.java.net/jive/thread.jspa?messageID=333650
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

antoniojsg
Offline
Joined: 2007-01-04
Points: 0

Also, the EJB is not part of the web application, I mean I am not building an EAR application.

I declared the EJB jar file as a library and included the library in the web application.

Deployed the EJB as a EJB module.

I need different web applications to use the same remote EJB module.

antoniojsg
Offline
Joined: 2007-01-04
Points: 0

thank you Sahoo.

I thought GlassFish required special deployment descriptors. But as you explain it is much more easy to do, so I will do it that way.

I know the page you recommend, so the link is below for someone reading this thread:

https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html

Regards,

Antonio

antoniojsg
Offline
Joined: 2007-01-04
Points: 0

Hello Sahoo,

Sorry for taking this matter again.

I defined several EJB 3 with remote interfaces.
I also defined Web Services which access this EJB through the remote interfaces.
Applications accesing webservices work fine.

Now I need that my visual JSF Web application to access the EJB´s remote interfaces.
I declared the EJB jar as a library.
I added the library as a resource to my Web Application, so I do not have the class not found problem.

Within a JSF page I declared the the @EJB to the remote interface.
When I try to access any method on the declared EJB I get a nullPointer Exception.

The glassFish documentation states that it resolves the dependencies automatically if only remote interfaces exists.

I am lost. Please advise. Thank you.

Antonio

Sahoo

Since you are getting NullPointerException, it probably means injection
manager didn't come to picture. Otherwise, you should have got a
NameNotFound kind of exception. Is there any such exception in
server.log? For injection to work, version in web.xml must be greater
than equal to 2.5. GlassFish v2 only supports version 2.5. Are you using
version=2.5 in your web.xml file? GlassFish document [1] suggests that
if your just specify @EJB, GlassFish will try to resolve an EJB with
global JNDI name as the name of the remote business interface name. If
your EJB has only one remote business interface name, then the EJB will
be bound with that name in JNDI and things would match, but if your EJB
has multiple remote business interfaces, matching can't take place. So,
I suggest, you browse the JNDI tree using admin console and see what
names are used by the EJB. If things still don't work, send us the code
that shows how you have defined/annotated your EJBs and how you are
injecting the EJB in your web app. In the worst case, I suggest you
specify a mappedName attribute while annotating the EJB and then use the
same in the web app. Something like this:

@Remote public interface Foo {}

@Stateless(mappedName="FOO")
public class FooBean implements Foo {

}

// In the JSF managed bean:
@EJB(mappedName="FOO") private Foo foo;

One more thing you can do is to see the generated ejb-jar.xml and
sun-ejb-jar.xml in
domains/domain1/applications/j2ee-modules//META-INF/
directory and see how GlassFish generates equivalent XML DD from
annotations to get a better understanding of the technology.

Thanks,
Sahoo

[1]
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#EJB_ejb-ref_ejb_...
glassfish@javadesktop.org wrote:
> Hello Sahoo,
>
> Sorry for taking this matter again.
>
> I defined several EJB 3 with remote interfaces.
> I also defined Web Services which access this EJB through the remote interfaces.
> Applications accesing webservices work fine.
>
> Now I need that my visual JSF Web application to access the EJB´s remote interfaces.
> I declared the EJB jar as a library.
> I added the library as a resource to my Web Application, so I do not have the class not found problem.
>
> Within a JSF page I declared the the @EJB to the remote interface.
> When I try to access any method on the declared EJB I get a nullPointer Exception.
>
> The glassFish documentation states that it resolves the dependencies automatically if only remote interfaces exists.
>
> I am lost. Please advise. Thank you.
>
> Antonio
> [Message sent by forum member 'antoniojsg' (antoniojsg)]
>
> http://forums.java.net/jive/thread.jspa?messageID=333486
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

antoniojsg
Offline
Joined: 2007-01-04
Points: 0

Thank you Sahoo.

I did browse the JNDI on the server console, there are NO remote interfaces listed for "Custom Resorces" nor "External Resources". But I am able to access the web services from client applications. Web services call remote EJB with remote interface.

Looks like deployment problem. Strange thing is that three days ago I did wrote a simple EJB with remote interface, deployed it, and I was able to call it from my web application. Now I have this error.

Version of GlassFish is V2 - Sun Java System Application Server 9.1_02 (build b04-fcs) on Centos 5.1 64bit.

web.xml vrsion is 2.5 (

Netbeans version is 6.5 on Windows XP.

Thanks for your help.

Sahoo

See reply in line...

glassfish@javadesktop.org wrote:
> Thank you Sahoo.
>
> I did browse the JNDI on the server console, there are NO remote interfaces listed for "Custom Resorces" nor "External Resources".
They don't seem to be right places to look at. Is their not an entry for
EJB? If you have successfully deployed your EJB with remote interfaces,
then the EJBs must have been bound to JNDI. The server.log should also
have some information about the EJB deployment. Try changing the log
level to FINE or something and you will get some more info.
> But I am able to access the web services from client applications. Web services call remote EJB with remote interface.
>
Is the EJB part of the webservice app?
> Looks like deployment problem. Strange thing is that three days ago I did wrote a simple EJB with remote interface, deployed it, and I was able to call it from my web application. Now I have this error.
>
> Version of GlassFish is V2 - Sun Java System Application Server 9.1_02 (build b04-fcs) on Centos 5.1 64bit.
>
> web.xml vrsion is 2.5 ( >
Before you look at the web-app, first ensure the EJB is deployed correctly.

Thanks,
Sahoo
> Netbeans version is 6.5 on Windows XP.
>
> Thanks for your help.
> [Message sent by forum member 'antoniojsg' (antoniojsg)]
>
> http://forums.java.net/jive/thread.jspa?messageID=333571
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

antoniojsg
Offline
Joined: 2007-01-04
Points: 0

Thank you Sahoo,

I did find the JNDI correctly this time with the option Application-Server/JNDI-Browsing.

Below is the listing from the server.
How do I have to declare the EJB in the web application ?
I need to use the DbPedidoPreventaRemote.

Jndi Entries Root (server)
com.mobilges.server.sales.comm.DbUsuarioRemote
com.mobilges.server.sales.comm.DbPedidoPreventaRemote__3_x_Internal_RemoteBusinessHome__
com.mobilges.server.sales.comm.DbInventarioSKURemote__3_x_Internal_RemoteBusinessHome__
jdbc
com.mobilges.server.sales.comm.DbInventarioMaestroUPCRemote#com.mobilges.server.sales.comm.DbInventarioMaestroUPCRemote
com.mobilges.server.sales.comm.DbInventarioPreciosRemote__3_x_Internal_RemoteBusinessHome__
com.mobilges.server.sales.comm.DbInventarioMaestroUPCRemote__3_x_Internal_RemoteBusinessHome__
com.mobilges.server.sales.comm.DbInventarioSKURemote
UserTransaction
com.mobilges.server.sales.comm.DbClienteRemote#com.mobilges.server.sales.comm.DbClienteRemote
com.mobilges.server.sales.comm.DbUsuarioRemote#com.mobilges.server.sales.comm.DbUsuarioRemote
com.mobilges.server.sales.comm.DbInventarioMaestroUPCRemote
com.mobilges.server.sales.comm.DbInventarioPreciosRemote#com.mobilges.server.sales.comm.DbInventarioPreciosRemote
com.mobilges.server.sales.comm.DbUsuarioRemote__3_x_Internal_RemoteBusinessHome__
com.mobilges.server.sales.comm.DbInventarioPreciosRemote
com.mobilges.server.sales.comm.DbClienteRemote
com.mobilges.server.sales.comm.DbInventarioSKURemote#com.mobilges.server.sales.comm.DbInventarioSKURemote
ejb
com.mobilges.server.sales.comm.DbPedidoPreventaRemote
com.mobilges.server.sales.comm.DbPedidoPreventaRemote#com.mobilges.server.sales.comm.DbPedidoPreventaRemote
com.mobilges.server.sales.comm.DbClienteRemote__3_x_Internal_RemoteBusinessHome__

antoniojsg
Offline
Joined: 2007-01-04
Points: 0

Dear Sahoo,

I have built a very simple EJB module with one stateles EJB with remote interface.

I deployed the EJB module successfully using mappedName annotation.

Then I built a very simple JSF application, injected @EJB reference with mappedName annotation within the managed SessionBean1.

It works fine to call the EJB from the action button.

I am also able to get a NameNotFound exception if I erase the mappedName annotation.

This leads to think that there is something else with the EJB module which includes JPA and web services.

Please advice if I it is ok with you to send you the files for your review .

Regards,

Antonio.

P.D.
I did include the examples if someone wants to use it as a basic reference.
testEjb is the web application
tejb is the ejb module.
remember to include tejb.jar in the libraries for the web application.

antoniojsg
Offline
Joined: 2007-01-04
Points: 0

Thank you Sahoo for your help.

Do you know about Glassfish documentation that explains how to achieve this ?

Any link will be appreciated.

Regards,

Antonio

Sahoo

What special instructions are you looking for? It should be as simple as
duplicating the interface classes in each war file, as if each war is
acting like an EJB client. Check GlassFish EJB FAQ (google with these
key words to get the link); you may find some sample code that shows how
to write an EJB client.

Thanks,
Sahoo

glassfish@javadesktop.org wrote:
> Thank you Sahoo for your help.
>
> Do you know about Glassfish documentation that explains how to achieve this ?
>
> Any link will be appreciated.
>
> Regards,
>
> Antonio
> [Message sent by forum member 'antoniojsg' (antoniojsg)]
>
> http://forums.java.net/jive/thread.jspa?messageID=294889
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Sahoo

Each deployed war and ejb-jar is treated as a separate application even
if they are deployed in the same instance. Only EJBs with remote
interface can be accessed from other applications. So, your EJBs must
have remote interfaces. To solve the class not found exception, you have
to duplicate the ejb remote interfaces and their dependencies in each
war file. This is a portable approach.

Thanks,
Sahoo

glassfish@javadesktop.org wrote:
> Hi,
>
> I need to know if this is possible:
>
> 1. -Deploy a EJB component to GlassFish with several session beans an entity beans
> and
> 2.- Deploy a web application that will use the Beans previously deployed in the standalone EJB component.
>
> I explain:
> Right know I am able to ensamble a EAR application with both EJB and WAR components, everything works fine. But my EJB component will be used by several web applications, so I do not want to create severa EAR projects all using the same ejb component.
>
> I want to deploy only one EJB component to GlassFish and then be able to deploy several WEB application that all will use the same EJB Component.
>
> I have deployed the standalone EJB component without errors. When I try to deploy the war file of the web application I get a classNotFound exception for the interface class name . I am not able to use JNDI correctly.
>
> Thank you for your help.
>
> Antonio
> [Message sent by forum member 'antoniojsg' (antoniojsg)]
>
> http://forums.java.net/jive/thread.jspa?messageID=294543
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net