1 Reply Latest reply: Jul 18, 2012 7:52 AM by René van Wijk RSS

    Embedded EJB Container // No EJBContainer provider available

    Justin James
      Hello Friends

      Environment :
      Weblogic12c
      JUnit4
      JRockit1.6

      Can you please share with me the EJBContainer.PROVIDER value while using weblogic12c.
      I created an EJB3.1 stateless session bean, now I'm trying to use embedded ejb container for JUnit test class within the same EJB project.

      I'm already followed this link - http://docs.oracle.com/javaee/6/tutorial/doc/gkcrr.html
      but no luck.While running JUnit test class, getting following exception you can find at the bottom this post.

      I'm using these packages from javax.ejb_3.1.0.jar
      import javax.ejb.embeddable.EJBContainer;
      import javax.ejb.spi.EJBContainerProvider;

      Note : The same test project is running well in glassfish server.

      Thanks in advance,
      Have more fun with Java.
      Justin.

      Exception :
      javax.ejb.EJBException: No EJBContainer provider available for requested provider: 
              javax.ejb.spi.EJBContainerProvider: no provider names had been found.
           at javax.ejb.embeddable.EJBContainer.reportError(EJBContainer.java:186)
           at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:121)
           at com.justin.math.ejb.test.CalculatorEJBJUTest.init(CalculatorEJBJUTest.java:31)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
           at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
           at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
           at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
           at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
           at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
           at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
           at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:684)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:391)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      Test Class :
      package com.justin.math.ejb.test;
      
      import static org.junit.Assert.*;
      
      import java.util.Properties;
      import javax.ejb.embeddable.EJBContainer;
      //import javax.ejb.spi.EJBContainerProvider;
      import javax.naming.NamingException;
      import org.junit.AfterClass;
      import org.junit.BeforeClass;
      import org.junit.Test;
      import com.justin.math.ejb.CalculatorEJB;
      
      public class CalculatorEJBJUTest {
           
           static EJBContainer ejbContainer; 
           static CalculatorEJB calculatorEJB;
           
           @BeforeClass
           public static void init() {          
                String globalJndiName = "java:global/classes/CalculatorEJB";
                //String localJndiName = "java:module/CalculatorEJB";
                Properties properties = new Properties();
                try {
                     properties.setProperty(EJBContainer.MODULES, "CalculatorEJB");
                     properties.setProperty(EJBContainer.PROVIDER, "javax.ejb.spi.EJBContainerProvider");
                              //Also tried without setting properties in WLS12c. Glassfish was fine without properties.
                     ejbContainer = EJBContainer.createEJBContainer(properties);
                              //Just trying both global and local jndi names
                     //calculatorEJB = (CalculatorEJB) ejbContainer.getContext().lookup(localJndiName);
                     calculatorEJB = (CalculatorEJB) ejbContainer.getContext().lookup(globalJndiName);
                     
                } catch (NamingException e) {
                     e.printStackTrace();
                }
           }
           
           @AfterClass
           public static void release() {
                if(ejbContainer != null)
                     ejbContainer.close();
           }
           
           @Test
           public void testAdd() {
                int result = calculatorEJB.add(1, 2);
                assertNotNull(result);
                assertEquals(3, result);
           }
           
           @Test
           public void testMultiply() {
                int result = calculatorEJB.multiply(1, 2);
                assertNotNull(result);
                assertEquals(2, result);
           }
      }
        • 1. Re: Embedded EJB Container // No EJBContainer provider available
          René van Wijk
          Some info can be found here: http://docs.oracle.com/cd/E24329_01/web.1211/e24972/embedejb.htm#EJBAD1403,
          also note here the EJB 3.1 Lite Functionality Supported in the Embedded EJB Container.

          This link http://docs.oracle.com/javaee/6/tutorial/doc/gkcrr.html (which you found) tells:

          "
          Running Embedded Applications
          The embedded container, the enterprise bean components, and the client all are executed in the same virtual machine using the same classpath. As a result, developers can run an application that uses the embedded container just like a typical Java SE application as follows:

          java -classpath mySessionBean.jar:containerProviderRuntime.jar:myClient.jar
          com.example.ejb.client.Main
          In the above example, mySessionBean.jar is an EJB JAR containing a local stateless session bean, containerProviderRuntime.jar is a JAR file supplied by the enterprise bean provider that contains the needed runtime classes for the embedded container, and myClient.jar is a JAR file containing a Java SE application that calls the business methods in the session bean through the embedded container.

          http://docs.oracle.com/javaee/6/api/javax/ejb/embeddable/EJBContainer.html
          "

          The containerproviderruntime.jar in WebLogic is called wlclient.jar (which contains a /javax/ejb/embeddable/EJBContainer.class).
          The wlclient.jar is located in the MIDDLEWARE_HOME/wlserver_12.1/server/lib directory.

          The weblogic.jar contains a provider implementation:
          public class Test {
              public static void main(String[] args) {
                  Map properties = new HashMap();
                  File module = new File("C:\\temp\\WebLogicServer\\voorbeelden\\LoadTest6\\out\\artifacts\\Model\\Model.jar");
                  properties.put(EJBContainer.MODULES, module);
                  properties.put(EJBContainer.PROVIDER, "weblogic.ejb.embeddable.EJBContainerProvider");
          
                  EJBContainer container = EJBContainer.createEJBContainer(properties);
                  Context context = container.getContext();
                  try {
                      Company company = (Company) context.lookup("java:global/ejb/Company");
                  } catch (NamingException e) {
                      e.printStackTrace();
                  }
                  container.close();
              }
          }
          It is better to create a fullclient jar (http://docs.oracle.com/cd/E17904_01/web.1111/e13717/jarbuilder.htm#BABCGHFH) - instead of looking for the classes you will constantly be missing.