I want to implement a kind of "plugin mechanism" using EJB3. I have two+ war's, each containing own bean types using Remote Interfaces defined in a separate project. Basically, I want my main Bean (Product) to always be deployed and provide a mechanism for other Beans (n different Project Beans) to register against. It is important that arbitrary Beans may register, as long as they have knowledge of the Product's Remote Interface. Sample code:
Product Bean
@Singleton
@ConcurrencyManagement(BEAN)
public class ProductBean implements ProductRemote, Serializable {
private static final long serialVersionUID = 4686943363874502919L;
private ProjectRemote project;
public void registerProject(ProjectRemote project) {
this.project = project;
}
public void something() {
if(project != null)
project.doSomething();
}
}
Project Bean
@ConcurrencyManagement(BEAN)
@Singleton
@Startup
public class ProjectBean implements ProjectRemote, Serializable {
private static final long serialVersionUID = -2034521486195622039L;
@EJB(lookup="java:global/product/ProductBean")
private ProductRemote product;
@PostConstruct
private void registerSelf() {
product.registerProject(this);
}
public void doSomething() {
System.err.println("FOOBAR");
}
}
Product Interface
@Remote
public interface ProductRemote {
public void registerProject(ProjectRemote project);
}
Project Interface
@Remote
public interface ProjectRemote {
public void doSomething();
}
Unfortunately, when I try to deploy the Project I get a ClassNotFoundException:
22:56:33,146 ERROR [org.jboss.as.controller.management-operation] (XNIO-1 task-7) JBAS014613: Operation ("add") failed - address: ([{"deployment" => "project-0.1-SNAPSHOT.war"}]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"project-0.1-SNAPSHOT.war\".component.ProjectBean.START" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"project-0.1-SNAPSHOT.war\".component.ProjectBean.START: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
Caused by: javax.ejb.EJBException: java.lang.RuntimeException: JBAS014154: Failed to marshal EJB parameters
Caused by: java.lang.RuntimeException: JBAS014154: Failed to marshal EJB parameters
Caused by: java.lang.ClassNotFoundException: com.xxx.test.project.ProjectBean from [Module \"deployment.product-0.1-SNAPSHOT.war:main\" from Service Module Loader]"}}
So my question is: is there any way to realize such a functionality? Or is it entirely impossible because of the different classpaths for each war?