Skip to content
Advertisement

Interface CDI wildfly external projects

So my idea is to have 3 projects:

  1. com.tests.interfaces
  2. com.tests.services
  3. com.tests.schedulers

com.tests.interfaces basically is:

@Remote
public interface IFoo {
    public String test(); 
}

com.tests.services is:

@Stateless(name = "IFoo")
public class FooBean implements IFoo {

    public String test() {
        return "Hello world";
    }

}

I am deploying the “services” project and it works fine using wildfly 24.0.0. Then I am trying to have another .war project called: com.tests.schedulers which looks like this:

@Stateless
public class TestEjb {

    @EJB(beanName = "IFoo")
    IFoo iFoo;
    
    public void teste() {
        iFoo.test();
    }
    
}

@Singleton
public class ExecutorMainframeProcessamento {

    @EJB
    TestEjb testEjb;

    @Schedule(second = "*/5", minute = "*", hour = "*", dayOfWeek = "*", persistent = false, info ="Test EJB")
    public void atSchedule() {
        testEjb.test();
    }
}

But it cant be deployed and this is the relevant part of wildfly’s (same server to all .wars) output:

Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0405: No Jakarta Enterprise Beans found with interface of type 'com.tests.interfaces.IFoo' and name 'IFoo' for binding com.tests.schedulers.TestEjb/iFoo

What am I missing or doing wrong?

Advertisement

Answer

You cannot refer a class in one WAR from a class in another WAR (unless both are in the same EAR).

This is by design!

Note that you can have all your projects in separate JAR files which are put in the same WAR file which then share their classpath when deployed. This is how it is typically done. Either convert your projects to Maven projects and refer to artifacts, or have your IDE help you create the single WAR.

Advertisement