3 Replies Latest reply on Nov 6, 2008 10:19 AM by Samuel Santos

    Embedded JBoss and MBeans

    Samuel Santos Newbie

      I've managed to get the Embedded JBoss deploy my EJBs successfully.
      Here are my configurations:

      Maven Surefire plugin:

      <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <version>2.4.3</version>
       <configuration>
       <excludes>
       <exclude>**/BaseTest.java</exclude>
       </excludes>
       <!-- for JDK6 Support -->
       <argLine>-Dsun.lang.ClassLoader.allowArraySyntax=true</argLine>
       <additionalClasspathElements>
       <additionalClasspathElement>${project.build.testOutputDirectory}/bootstrap</additionalClasspathElement>
       </additionalClasspathElements>
       </configuration>
      </plugin>
      


      Maven Embedded JBoss dependencies:
      <dependency>
       <groupId>org.jboss.embedded</groupId>
       <artifactId>jboss-embedded-all</artifactId>
       <version>beta3.SP2</version>
       <exclusions>
       <exclusion>
       <groupId>org.jboss.embedded</groupId>
       <artifactId>jboss-embedded</artifactId>
       </exclusion>
       </exclusions>
      </dependency>
      <dependency>
       <groupId>org.jboss.embedded</groupId>
       <artifactId>hibernate-all</artifactId>
       <version>beta3.SP2</version>
      </dependency>
      <dependency>
       <groupId>org.jboss.embedded</groupId>
       <artifactId>thirdparty-all</artifactId>
       <version>beta3.SP2</version>
      </dependency>
      <dependency>
       <groupId>org.jboss.embedded</groupId>
       <artifactId>jboss-embedded</artifactId>
       <version>beta3.SP2</version>
       <!--exclusions>
       <exclusion>
       <groupId>org.jboss.microcontainer</groupId>
       <artifactId>jboss-deployers-client-spi</artifactId>
       </exclusion>
       </exclusions-->
      </dependency>
      <dependency>
       <groupId>jboss</groupId>
       <artifactId>jboss-annotations-ejb3</artifactId>
       <version>4.2.3.GA</version>
      </dependency>
      

      I need the jboss-annotations-ejb3 dependency so I can use the @LocalBinding(jndiBinding = "MyService") annotation.

      But even with this dependency I have to lookup my Bean like this:
      InitialContext ctx = new InitialContext();
      service = (MyService) ctx.lookup("MyServiceBean/local");
      

      Like the JBoss AS, it should work like this instead:
      InitialContext ctx = new InitialContext();
      service = (MyService) ctx.lookup("MyService");
      


      OK, I can live with this.
      But one thing I can't get to work is to deploy my MBeans with the Embedded JBoss.

      I'm using the following annotations:
      @Service(objectName = "com.foo.bar:service=MyOtherService")
      @Management(MyOtherService.class)
      

      In my EJBs I locate the MBeans like this:
      MBeanServer server = MBeanServerLocator.locate();
      myOtherService= (MyOtherService) MBeanProxyExt.create(MyOtherService.class,
       "com.foo.bar:service=MyOtherService", server);
      


      This works fine with JBoss AS and Embeddable EJB 3.0.
      I'm getting it wrong?
      Does Embedded JBoss support MBeans?

      Thanks for your help.

      --
      Samuel Santos

        • 1. Re: Embedded JBoss and MBeans
          Kamil Demecki Novice

          I think locating mbeans works even on J2SE. But creating I dont know...

          Mayby try deploy mbeans in *service.xml in standard jboss way ?

          • 2. Re: Embedded JBoss and MBeans
            Rick Reumann Newbie

            Silenius, would you mind terribly providing me or this forum board with what else you had to do to get everything working? I'm pulling my hair out trying to look at different ways to get a good Maven2/Embedded JBoss example to work for me! There is so little out there on that, and things that I find are always conflicting with the other ways I see things being done. I've yet to find a GOOD clean example of what needs to be done. I was trying to follow the way the hibernate cavaetemptor project thing is doing it, but it's also conflicting with the way Christian seems to be doing things here http://in.relation.to/1380.lace

            I'll check the posts here and think others would benefit from what you found as well, otherwise could you possibly send to rickcr at gmail dot com I'd be very grateful.

            Thanks

            • 3. Re: Embedded JBoss and MBeans
              Samuel Santos Newbie

              Kamil:
              Deploying mbeans in *service.xml files is not an option.
              This is a big project already in production.
              I just need to add some features to it and have my unit tests running.

              rickcr:
              The only thing that is missing from my first message is how to start the Embedded JBoss. This is how I did it:

              private static void startupEmbeddedJboss() {
               try {
               if (!Bootstrap.getInstance().isStarted()) {
               Bootstrap.getInstance().bootstrap();
               Bootstrap.getInstance().deploy(makeURLForDir("target/classes"));
               }
               } catch (DeploymentException e) {
               LOGGER.error(e.getMessage(), e);
               } catch (IOException e) {
               LOGGER.error(e.getMessage(), e);
               }
              }
              
              private static void shutdownEmbeddedJboss() {
               if (System.getProperty("shutdown.embedded.jboss") != null) {
               Bootstrap.getInstance().shutdown();
               }
              }