9 Replies Latest reply on Nov 13, 2015 6:07 AM by Martin Both

    Embeddable EJB Container JBoss 7.1.1

    Christoph Albrecht Newbie

      Has anyone been able to get EJB 3.1 Embeddable to work with JBoss 7.1.1.Final yet?

      Following instructions on https://community.jboss.org/wiki/EJB31Embeddable#comment-1206  I made an JBoss instance boot up in JVM.

      For testing and deploying I also created a very simple test-ejb.jar, containing nothing more than a single stateless ejb class.

       

      JBoss is starting up succesfully. The test-ejb.jar is been recognized as an ejb-jar and JBoss wants to start deployment when an error is coming up.

       

      import java.io.File;
      import java.util.*;
      import javax.ejb.embeddable.EJBContainer;
      
      public class TestEJBEmb {
          public TestEJBEmb() {
      
              System.setProperty("org.jboss.as.embedded.ejb3.BARREN", "true");
              System.setProperty("jboss.home", "C:/Programme/jboss-as-7.1.1.Final");
              System.setProperty("jboss.home.dir", "C:/Programme/jboss-as-7.1.1.Final");
              
              Map<String, Object> props = new HashMap<String, Object>();
      
              File[] ejbModules = new File[1];
              ejbModules[0] = new File("c:/Users/ca/Desktop/test-ejb.jar");
      
              props.put(EJBContainer.MODULES, ejbModules);
              EJBContainer container = EJBContainer.createEJBContainer(props);
          }
      
          public static void main(String[] args) {
              new TestEJBEmb();
          }
      }
      

       

       

      14:43:18,490 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 3446ms - Started 149 of 227 services (76 services are passive or on-demand)
      14:43:18,801 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "test-ejb.jar"
      14:43:19,445 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.module.service."deployment.test-ejb.jar".main: org.jboss.msc.service.StartException in service jboss.module.service."deployment.test-ejb.jar".main: Failed to load module: deployment.test-ejb.jar:main
          at org.jboss.as.server.moduleservice.ModuleLoadService.start(ModuleLoadService.java:91)
          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [rt.jar:1.6.0_31]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.6.0_31]
          at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_31]
      Caused by: org.jboss.modules.ModuleNotFoundException: Module Classpath:main is not found in local module loader @7c4c51 (roots: C:\Programme\jboss-as-7.1.1.Final\modules)
          at org.jboss.modules.LocalModuleLoader.findModule(LocalModuleLoader.java:126) [jboss-modules-1.1.2.GA.jar:1.1.2.GA]
          at org.jboss.modules.ModuleLoader.loadModuleLocal(ModuleLoader.java:275) [jboss-modules-1.1.2.GA.jar:1.1.2.GA]
          at org.jboss.modules.ModuleLoader.preloadModule(ModuleLoader.java:222) [jboss-modules-1.1.2.GA.jar:1.1.2.GA]
          at org.jboss.modules.LocalModuleLoader.preloadModule(LocalModuleLoader.java:94) [jboss-modules-1.1.2.GA.jar:1.1.2.GA]
          at org.jboss.modules.Module.addPaths(Module.java:851) [jboss-modules-1.1.2.GA.jar:1.1.2.GA]
          at org.jboss.modules.Module.link(Module.java:1206) [jboss-modules-1.1.2.GA.jar:1.1.2.GA]
          at org.jboss.modules.Module.relinkIfNecessary(Module.java:1235) [jboss-modules-1.1.2.GA.jar:1.1.2.GA]
          at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:208) [jboss-modules-1.1.2.GA.jar:1.1.2.GA]
          at org.jboss.as.server.moduleservice.ModuleLoadService.start(ModuleLoadService.java:70)
          ... 5 more
      
      14:43:19,668 INFO  [org.jboss.as.server] (pool-9-thread-1) JBAS015870: Deploy of deployment "test-ejb.jar" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.module.service.\"deployment.test-ejb.jar\".main" => "org.jboss.msc.service.StartException in service jboss.module.service.\"deployment.test-ejb.jar\".main: Failed to load module: deployment.test-ejb.jar:main"}}
      14:43:19,690 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015877: Stopped deployment test-ejb.jar in 21ms
      14:43:19,693 INFO  [org.jboss.as.controller] (pool-9-thread-1) JBAS014774: Service status report
      JBAS014777:   Services which failed to start:      service jboss.module.service."deployment.test-ejb.jar".main: org.jboss.msc.service.StartException in service jboss.module.service."deployment.test-ejb.jar".main: Failed to load module: deployment.test-ejb.jar:main
      

       

      Any clues? Any help is very much appreciated.

       

      Related discussions: https://community.jboss.org/message/732179

       

      Thanks in advance.

        • 1. Re: Embeddable EJB Container JBoss 7.1.1
          Jean-Pierre RIO Newbie

          Hello,

           

          I have the same problem. When I start a container this way, it works :

           

          @Test

          public void test() throws Exception {

                    String jbossHomeDir = "E:\\dev_station\\java_station\\Serveurs\\jboss-as-7.1.1.Final";

                    System.setProperty("jboss.home.dir", jbossHomeDir);

           

              StandaloneServer server = EmbeddedServerFactory.create(new File(

                                        jbossHomeDir), System.getProperties(), System.getenv(),

                                        "org.jboss.logmanager");

           

           

                    server.start();

                    server.deploy(new File("target/classes"));

                    Context namingContext = server.getContext();

          }

           

          When I add this in my code : System.setProperty("org.jboss.as.ejb3.EMBEDDED", "true"), i can reproduce the problem ("Module Classpath:main is not found in local module loader").

          This property is set in JBossStandaloneEJBContainerProvider.createEJBContainer(Map<?, ?> properties) and used in EjbDependencyDeploymentUnitProcessor. deploy(DeploymentPhaseContext phaseContext).

           

          I'm not "JBoss Modules Champion" enough to solve the pb, but maybe someone can use those observations to fix it...

          • 2. Re: Embeddable EJB Container JBoss 7.1.1
            Steven Simpson Newbie

            Does anyone have any input on this?  I am seeing the exact same error and I have searched a ton for similar problems and I am stuck.  Thanks!

            • 3. Re: Embeddable EJB Container JBoss 7.1.1
              C Str Newbie

              Adding an exclusion <module name="Classpath"/> solved it for me in (in JBoss EAP 6). I.e. my META-INF/jboss-deployment-structure.xml now looks like this:

               

              {code:xml}

              <?xml version="1.0" encoding="ISO-8859-1"?>

              <jboss-deployment-structure>

                  <deployment>

                      <module-alias name="..."/>

                      <dependencies>

                          ...

                      </dependencies>

                      <exclusions>

                          ...

                          <module name="Classpath"/>

                      </exclusions>

                  </deployment>

              </jboss-deployment-structure>

              {code}

              • 4. Re: Embeddable EJB Container JBoss 7.1.1
                Gustavo Orair Newbie

                C Srt,

                Could you please provide me a working example?

                 

                Thanks.

                • 5. Re: Embeddable EJB Container JBoss 7.1.1
                  C Str Newbie

                  http://stackoverflow.com/questions/15032303 describes a remote SlSB invocation that i finally got working.

                  • 6. Re: Embeddable EJB Container JBoss 7.1.1
                    Gustavo Orair Newbie

                    Thanks C Str,

                    but to be sincere I think this example is too complicated.

                    I just want to use the Embeddable API to run Jboss embedded inside a Junit test.

                    I really googled a lot and couldn't find a working solution. Jboss docs just rely on old ejb3-embedded.

                     

                    Since arquillian has not a working solution for Jboss Embedded for now, I am figuring out if this is really possible to accomplish.

                    • 7. Re: Embeddable EJB Container JBoss 7.1.1
                      C Str Newbie

                      I'll try to extract a minimal working example from my stackoverflow post soon. But I don't know arquillian, so it will be plain JUnit.

                      • 8. Re: Embeddable EJB Container JBoss 7.1.1
                        C Str Newbie

                        Uploaded source and Eclipse projects: http://www.file-upload.net/download-7480628/HelloWorldEmbeddedEjb.zip.html, see comment in http://stackoverflow.com/questions/15032303/#comments-15073153.

                         

                        However, my promise to provide a JUnit example was too optimistic. I don't know how to properly combine it with org.jboss.modules.Main. For JUnit 3, you could probably call

                        test.util.JbossModulesMain -mp ... -dep ... junit.textui.TestRunner YourTest
                        

                        but it wouldn't look like a JUnit invocation to an IDE (e.g. Eclipse would not show the run in the JUnit view).

                        • 9. Re: Embeddable EJB Container JBoss 7.1.1
                          Martin Both Newbie

                          After a lot of debugging work I've got a working solution for JUnit-Test with EJBContainer and JBoss EAP 6.4.

                           

                          The key think was to build a class as addition to the jboss-modules.jar. (Java code is below.)

                          I put my class EmbeddedModuleClassLoader into a jar called jboss-modules-fix.jar and add this jar to the java class path.

                          Using my class it is now possible to prepare the module class loader of JBoss before creating the EJBContainer.

                           

                          1. First step is to set the java system properies like this (please replace:${} variables by your values)

                          jboss.home=${el.program.dir}/jboss-eap-6.4

                          jboss.home.dir=${jboss.home}

                          jboss.server.base.dir=${el.eclipse.workspace}/Servers/JBossEAP6.4/standalone

                           

                          classpath is set to ${jboss.home}/jboss-modules.jar and ${el.eclipse.workspace}/Servers/JBossEAP6.4/jboss-modules-fix.jar

                           

                          jboss.modules.dir=${jboss.home}${file.separator}modules

                          module.path=${el.eclipse.workspace}/Servers/JBossEAP6.4/modules\${path.separator}${jboss.modules.dir}

                           

                          # Set this system packages

                          jboss.modules.system.pkgs=javax.ejb.spi,\

                          javax.ejb.embeddable,\

                          javax.ejb,\

                          javax.jws,\

                          javax.xml,\

                          javax.interceptor,\

                          javax.annotation

                           

                          2. Second prepare the module class loader with that java code:

                           

                          //ModuleClassLoader modClLdE= EmbeddedModuleClassLoader.setup();

                          Class<?> classEMCLH= Class.forName(

                                  "org.jboss.modules.EmbeddedModuleClassLoader", true,

                                  yourCurrentOrSelfmadeClassLoader);

                          Method mSetup= classEMCLH.getDeclaredMethod("setup", Properties.class);

                          Object embeddedMCL= mSetup.invoke(null, new Properties());

                           

                          providerClassLoader= (ClassLoader)embeddedMCL;

                           

                          3. Third load the EJBContainerProvider and create the EJBContainer with that code.

                           

                          EJBContainerProvider provider=

                              loadEjbContainerProvider(providerClassLoader);

                           

                          EJBContainer container= provider.createEJBContainer(configProps);

                           

                          static EJBContainerProvider loadEjbContainerProvider(

                              ClassLoader providerClassLoader) throws Exception {

                           

                              ServiceLoader<EJBContainerProvider> providers= ServiceLoader.load(

                                      EJBContainerProvider.class, providerClassLoader);

                              EJBContainerProvider selectedProvider= null;

                              for(EJBContainerProvider provider: providers){

                                  if(selectedProvider != null){

                                      System.err.println("EJBContainerProvider1 " + selectedProvider.getClass().getName());

                                      System.err.println("EJBContainerProvider2 " + provider.getClass().getName());

                                      throw new Exception("More than one EJBContainerProvider found!");

                                  }

                                  selectedProvider= provider;

                              }

                              if(selectedProvider == null){

                                  throw new Exception("No EJBContainerProvider found!");

                              }

                              System.out.println("EJBContainerProvider is" + selectedProvider.getClass().getName());

                              return selectedProvider;

                          }

                           

                          4. Here is the code for the class EmbeddedModuleClassLoader

                           

                          package org.jboss.modules;

                           

                          import static org.jboss.modules.SecurityActions.setContextClassLoader;

                          import java.util.Properties;

                          import __redirected.__JAXPRedirected;

                           

                          public class EmbeddedModuleClassLoader {

                           

                              /** This code is similar to the code in the org.jboss.modules.Main.class

                               * of JBoss.

                               *

                               * @param propArgs Arguments

                               * @return ClassLoader of the Module "org.jboss.as.embedded". The

                               *    ContextClassLoader of the Thread is set to the bootClassLoader.

                               * @throws Exception

                               */

                              public static ModuleClassLoader setup(Properties propArgs) throws Exception{

                                

                                  /* Wir richten den JBoss ModuleLoader genauso ein, wie in der Methode

                                   * "org.jboss.as.embedded.EmbeddedServerFactory.setupModuleLoader()".

                                   * Wir setzen voraus, dass die SystemProperties module.path und

                                   * jboss.modules.system.pkgs bereits richtig gesetzt sind.

                                   */

                                  final String classPath= System.getProperty("java.class.path");

                                  System.out.println("java.class.path=" + classPath);

                                  System.out.println("JBoss module.path="

                                          + System.getProperty("module.path"));

                                  System.out.println("jboss.modules.system.pkgs="

                                          + System.getProperty("jboss.modules.system.pkgs"));

                                

                                  /* The default boot module loader is an instance of the LocalModuleLoader,

                                   * unless the "boot.module.loader" system property is set.

                                   * The LocalModuleLoader is using the "module.path" system property

                                   * or the JAVA_MODULEPATH environment variable to get the list of

                                   * module repository roots.

                                   */

                                  ModuleLoader envModLd= DefaultBootModuleLoaderHolder.INSTANCE;

                                

                                  ModuleLoader bootModLd= new ClassPathModuleLoader(envModLd,

                                          null, classPath, null);

                                  ModuleIdentifier bootModLdId= ModuleIdentifier.CLASSPATH;

                                

                                  /* It just sets the boot module loader to avoid the default value

                                   * in Module.getBootModuleLoader().

                                   */

                                  Module.initBootModuleLoader(bootModLd);

                                

                                  final String jaxpmodule= propArgs.getProperty("jaxpmodule");

                                  if(jaxpmodule != null){

                                      ModuleIdentifier jaxpModuleIdentifier= ModuleIdentifier.fromString(

                                              jaxpmodule);

                                      __JAXPRedirected.changeAll(jaxpModuleIdentifier, bootModLd);

                                  }else {

                                      __JAXPRedirected.changeAll(bootModLdId, bootModLd);

                                  }

                           

                                  Module bootMod= bootModLd.loadModule(bootModLdId);

                           

                                  ModularURLStreamHandlerFactory.addHandlerModule(bootMod);

                                  ModularContentHandlerFactory.addHandlerModule(bootMod);

                           

                                

                                  final ModuleClassLoader bootClassLoader= bootMod.getClassLoaderPrivate();

                                  setContextClassLoader(bootClassLoader);

                           

                                  ModuleIdentifier mIdEmbedded= ModuleIdentifier.fromString(

                                          "org.jboss.as.embedded");

                                  Module modEmbedded= bootModLd.loadModule(mIdEmbedded);

                                  return modEmbedded.getClassLoader();

                              }

                          }

                           

                          Martin Both