Skip to main content

ejb jar, war, ear and dependecy injection

No replies
mgfarme
Offline
Joined: 2010-05-24

I am having issues getting a simple EJB entity, built into an EJB jar file, dependency injected into a session bean within a war file. The war file session bean is annotated as a restful service . Both the war and ejb-jar file are in an ear file.

The EJB looks like this:

package test;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

@Stateless
public class rest1ejb implements rest1ejbLocal {
@Override
public String getData()
{
return "hello EJB world!";
}
}

The war session bean looks like this:

package testrs;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import test.rest1ejbLocal;

@Stateless
@Path("getName")
public class rest_test {

@EJB
private rest1ejbLocal ejb;

@GET
public String getData()
{
if (ejb != null)
return ejb.getData();
else
return "No EJB1!!";
}
}

but when I deploy, I get "java.lang.NoClassDefFoundError: testrs/rest_test". It makes no difference whether I package the local interface with the war (i.e. in the lib dir) or not. I guess it's a classloader issue, but if I instrument the MANIFEST.MF file to add a Class-Path entry, specifying the ejb-jar file, it fails to deploy - it seems that glassfish tries to resolve the refernce to the exploded ear file, which no longer contains the jar, but the expanded jar. Also, I fail to see why the rest_test class is trying to be located outside of the war classloader (its not referenced by the Entity bean or the ejb-jar file.....

If I remove the @Stateless, then it deploys, but when I go to the url for the restful service, I get the "No EJB1!" reported i.e. no dependency injection.

Note, that I successfully get DI between EJB sessions beans when there are multiple ejb-jar in the ear file. All the text I have see relating to restful services, shows the entity beans class file located under the WEB-INF/classes - but I want to keep the entity beans in their own ejb-jar file.

I am using netbeans 6.1m1 and glassfish 3.0.1 build 19

Thanks

Martin