You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by jolinnen <jo...@linnenkohl.org> on 2016/05/12 15:07:56 UTC

Using @EJB from an EAR app inside a webservice in a different WAR

Hello,
I face a problem for which i cannot find a solution although I did a lot of
reading, coding and testing.
My situation:

I've have an EAR with an EJB like this:

@Stateless
@Startup
@Local(WMAuthEJB.class)
@Remote(WMAuthEJB.class)
public class WMAuthEJBImpl
       implements WMAuthEJB
{
}

I deploy the EAR in the app-directory and on the log of TomEE I find this
(amongst others):

INFO:
Jndi(name=global/authservices_ear-1.0/authservices_ejb-1.0/WMAuthEJBImpl!wm.administration.ejb.WMAuthEJB)
--> Ejb(deployment-id=WMAuthEJBImpl)

and I can use it in a remote client. So that's fine.

But now I must use this EJB  inside a rest webservice, I tried this (amongst
others)

// @Stateless
// @Singleton
@Path("/")
public class WMAuthService
{
    @EJB
    private WMAuthEJB                        wmauth;
}

After deploying the myservice.war in webapps the TomEE log say

INFO: Skipping deployment of Class class myservice due to a
NoClassDefFoundError: LWMAuthEJB;

To tell the truth I have no idea what to do or what to read next. Sorry for
that but I had a simolar situation on JBoss with a solution of an xml config
file (jboss-deployme-structure.xml).

Does someone has an advice for me?

Many Thanks

jolinnen







--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Using-EJB-from-an-EAR-app-inside-a-webservice-in-a-different-WAR-tp4678407.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Using @EJB from an EAR app inside a webservice in a different WAR

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Can be linked to a dependency too.

Maybe provide a sample on github reproducing the issue (using
tomee-maven-plugin is really a good and fast way to share it)

"ear lib" is clearly visible from the webapp - we have tests for that - so
issue is probably a bit more nasty.


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-05-13 6:11 GMT+02:00 jolinnen <jo...@linnenkohl.org>:

> Hello again,
>
> no, contrary:  the EJB is in an EAR (deployed in apps)  while the
> restservice is in the WAR (deployed in webapps).
> My version: Apache Tomcat (TomEE)/7.0.68 (1.7.4) (not very old).
>
> I will make some further testing, for me it seems that components in apps
> and webapps cannot see each other.
>
> Thank you.
> jolinnen
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Using-EJB-from-an-EAR-app-inside-a-webservice-in-a-different-WAR-tp4678407p4678418.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: Using @EJB from an EAR app inside a webservice in a different WAR

Posted by jolinnen <jo...@linnenkohl.org>.
Hello again,

no, contrary:  the EJB is in an EAR (deployed in apps)  while the
restservice is in the WAR (deployed in webapps).
My version: Apache Tomcat (TomEE)/7.0.68 (1.7.4) (not very old).

I will make some further testing, for me it seems that components in apps
and webapps cannot see each other.

Thank you.
jolinnen



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Using-EJB-from-an-EAR-app-inside-a-webservice-in-a-different-WAR-tp4678407p4678418.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Using @EJB from an EAR app inside a webservice in a different WAR

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Well @Inject will not rely on JNDI and NoClassDefFoundError means your
service can't see your EJB. Is the EJB in the webapp and the service in the
ear lib part?

Also didn't see the version you are using of tomee, are you using last ones?


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-05-12 17:45 GMT+02:00 jolinnen <jo...@linnenkohl.org>:

> Hi,
> thanks for your quick reply.
> Okay, I change to
>
> @Stateless
> @Startup
> @LocalBean
> @Remote(WMAuthEJB.class)
> public class WMAuthEJBImpl
>        implements WMAuthEJB
> {
> }
>
> and
>
> // @Stateless
> // @Singleton
> @Path("/")
> public class WMAuthService
> {
>     /*
>     @EJB
>     private WMAuthEJB                        wmauth;
>     */
>     @Inject
>     private WMAuthEJBImpl                    wmauth;
>
> and the error has changed:
>
> SEVERE: error invoking
> org.apache.tomee.webservices.TomeeJaxRsService@23d29c10
> java.lang.NoClassDefFoundError: LWMAuthEJBImpl;
>         at java.lang.Class.getDeclaredFields0(Native Method)
>         at java.lang.Class.privateGetDeclaredFields(Class.java:2317)
>         at java.lang.Class.getDeclaredFields(Class.java:1762)
>         at
>
> org.apache.openejb.server.cxf.rs.Contexts.findContextFields(Contexts.java:53)
>         at
>
> org.apache.openejb.server.cxf.rs.CdiResourceProvider.findContexts(CdiResourceProvider.java:131)
>         at
>
> org.apache.openejb.server.cxf.rs.CdiResourceProvider.<init>(CdiResourceProvider.java:103)
>         at
>
> org.apache.openejb.server.cxf.rs.OpenEJBPerRequestPojoResourceProvider.<init>(OpenEJBPerRequestPojoResourceProvider.java:28)
>         at
>
> org.apache.openejb.server.cxf.rs.CxfRsHttpListener.deployApplication(CxfRsHttpListener.java:522)
>         at
>
> org.apache.openejb.server.rest.RESTService.deployApplication(RESTService.java:464)
>         at
>
> org.apache.openejb.server.rest.RESTService.afterApplicationCreated(RESTService.java:275)
>         at
>
> org.apache.tomee.webservices.TomeeJaxRsService.afterApplicationCreated(TomeeJaxRsService.java:53)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>
> CDI complains. Maybe the EAR in apps have a different JNDI context than the
> WAR in webapps? is it possible to browse the context?
>
> Thanks again.
>
> Cheers
>
> jolinnen
>
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Using-EJB-from-an-EAR-app-inside-a-webservice-in-a-different-WAR-tp4678407p4678409.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: Using @EJB from an EAR app inside a webservice in a different WAR

Posted by jolinnen <jo...@linnenkohl.org>.
Hi,
thanks for your quick reply.
Okay, I change to

@Stateless
@Startup
@LocalBean
@Remote(WMAuthEJB.class)
public class WMAuthEJBImpl
       implements WMAuthEJB
{
}

and

// @Stateless
// @Singleton
@Path("/")
public class WMAuthService
{
    /*
    @EJB
    private WMAuthEJB                        wmauth;
    */
    @Inject
    private WMAuthEJBImpl                    wmauth;

and the error has changed:

SEVERE: error invoking
org.apache.tomee.webservices.TomeeJaxRsService@23d29c10
java.lang.NoClassDefFoundError: LWMAuthEJBImpl;
        at java.lang.Class.getDeclaredFields0(Native Method)
        at java.lang.Class.privateGetDeclaredFields(Class.java:2317)
        at java.lang.Class.getDeclaredFields(Class.java:1762)
        at
org.apache.openejb.server.cxf.rs.Contexts.findContextFields(Contexts.java:53)
        at
org.apache.openejb.server.cxf.rs.CdiResourceProvider.findContexts(CdiResourceProvider.java:131)
        at
org.apache.openejb.server.cxf.rs.CdiResourceProvider.<init>(CdiResourceProvider.java:103)
        at
org.apache.openejb.server.cxf.rs.OpenEJBPerRequestPojoResourceProvider.<init>(OpenEJBPerRequestPojoResourceProvider.java:28)
        at
org.apache.openejb.server.cxf.rs.CxfRsHttpListener.deployApplication(CxfRsHttpListener.java:522)
        at
org.apache.openejb.server.rest.RESTService.deployApplication(RESTService.java:464)
        at
org.apache.openejb.server.rest.RESTService.afterApplicationCreated(RESTService.java:275)
        at
org.apache.tomee.webservices.TomeeJaxRsService.afterApplicationCreated(TomeeJaxRsService.java:53)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

CDI complains. Maybe the EAR in apps have a different JNDI context than the
WAR in webapps? is it possible to browse the context?

Thanks again.

Cheers

jolinnen




--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Using-EJB-from-an-EAR-app-inside-a-webservice-in-a-different-WAR-tp4678407p4678409.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Using @EJB from an EAR app inside a webservice in a different WAR

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

did you try to use 2 interfaces (one can extend the other but ensure type
is different for local and remote). Alternative is to use @LocalBean
instead of Local and inject the impl.


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-05-12 17:07 GMT+02:00 jolinnen <jo...@linnenkohl.org>:

> Hello,
> I face a problem for which i cannot find a solution although I did a lot of
> reading, coding and testing.
> My situation:
>
> I've have an EAR with an EJB like this:
>
> @Stateless
> @Startup
> @Local(WMAuthEJB.class)
> @Remote(WMAuthEJB.class)
> public class WMAuthEJBImpl
>        implements WMAuthEJB
> {
> }
>
> I deploy the EAR in the app-directory and on the log of TomEE I find this
> (amongst others):
>
> INFO:
>
> Jndi(name=global/authservices_ear-1.0/authservices_ejb-1.0/WMAuthEJBImpl!wm.administration.ejb.WMAuthEJB)
> --> Ejb(deployment-id=WMAuthEJBImpl)
>
> and I can use it in a remote client. So that's fine.
>
> But now I must use this EJB  inside a rest webservice, I tried this
> (amongst
> others)
>
> // @Stateless
> // @Singleton
> @Path("/")
> public class WMAuthService
> {
>     @EJB
>     private WMAuthEJB                        wmauth;
> }
>
> After deploying the myservice.war in webapps the TomEE log say
>
> INFO: Skipping deployment of Class class myservice due to a
> NoClassDefFoundError: LWMAuthEJB;
>
> To tell the truth I have no idea what to do or what to read next. Sorry for
> that but I had a simolar situation on JBoss with a solution of an xml
> config
> file (jboss-deployme-structure.xml).
>
> Does someone has an advice for me?
>
> Many Thanks
>
> jolinnen
>
>
>
>
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Using-EJB-from-an-EAR-app-inside-a-webservice-in-a-different-WAR-tp4678407.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>