2 Replies Latest reply on Mar 21, 2013 6:04 AM by andrewwinter77

    Add module via Management API in AS 7.2

    andrewwinter77

      Hi all

       

      I know the CLI has been updated in AS 7.2 / EAP 6.1.0 to support adding modules. Does anyone know if the native management API (jboss-as-controller-client) also supports adding modules? If so, are there any docs or sample code showing how to do this?

       

      Thanks!

       

      Andrew.

        • 1. Re: Add module via Management API in AS 7.2
          jaysensharma

          Hi,

           

              No, I do not think Creation of Module is possible via   Management API.

           

              However you can use CLI based java API to achieve the same:

           

           

          import java.io.IOException;
          import java.util.Map;
          import org.jboss.as.cli.CommandContext;
          import org.jboss.as.cli.CommandContextFactory;
          import org.jboss.as.cli.CommandLineException;
           public class ModuleAdd
          {
             public static void main(String[] args) throws CommandLineException, IOException
             {
                String host = "localhost";
                int port = 9999;
                ModuleAdd moduleAdd=new ModuleAdd();
                CommandContext ctx = CommandContextFactory.getInstance().newCommandContext("admin","admin123".toCharArray());
                ctx.connectController(host, port);
                moduleAdd.createSecurityDoModuleAdd(ctx);      
                ctx.disconnectController();
             }
          
          
                 public void createSecurityDoModuleAdd(CommandContext ctx)
                 {   
                   System.out.println("Setting up the module with CLI");
                   try {               
                          String command="module add --name=aaa.bbb --resources=/NotBackedUp/DELETE/ojdbc6.jar --dependencies=javax.api,javax.transaction.api";
                          ctx.handle(command);
                       } 
                   catch (CommandLineException e) 
                       {
                          e.printStackTrace();
                       } 
                   finally 
                       {
                          ctx.terminateSession();
                       }          
                  }
          }
          

           

           

           

            For example when you open a Terminal and export JBOSS_HOME in the terminal  and then when you run the above code you wil see a Module is added in JBoss AS7.1.3  or higher version of it as following:

           

           

          AS7.1.3/modules

          /aaa/

          └── bbb

              └── main

                  ├── module.xml

                  └── ojdbc6.jar

           

           

          module.xml as following:

          =================

          <?xml version="1.0" ?>
          <module xmlns="urn:jboss:module:1.1" name="aaa.bbb">
              <resources>
                  <resource-root path="ojdbc6.jar"/>
              </resources>
              <dependencies>
                  <module name="javax.api"/>
                  <module name="javax.transaction.api"/>
              </dependencies>
          </module>
          
          1 of 1 people found this helpful
          • 2. Re: Add module via Management API in AS 7.2
            andrewwinter77

            Thanks for the tip, Jay. Having to rely on the filesystem isn't ideal but it's a good-enough workaround for me for now.

             

            Thanks!

             

            Andrew.