1 Reply Latest reply on Jul 20, 2011 9:14 AM by ymaraner

    Running Embedded JBoss via ANT with AS 6.0.0.Final

    ymaraner

      I am considering using JBoss Embedded AS within a java swing application so that I can use JEE services to support remote execution of work on multiple remote clients.

      As a first start, I've been trying to get a JBoss Embedded AS 6.0.0.final to start up and then shut down. It seems simple enough, but it keeps hanging during startup. I added some debug print statements to try to see what is going on, and it seems to get hung in the STARTING state.

      We are not a maven shop, so I've been using ant to build and run the simple prototype.

       

      Here's my build file:

      {code:xml}

      <project name="HelloWorld" default="compile" basedir=".">
        <property name="proj.name" value="HelloWorld"/>
        <property name="proj.version" value="1.0"/>


        <property environment="env"/>
        <property name="src.java.dir" value="${basedir}/src"/>
        <property name="src.etc.dir" value="${basedir}/etc"/>
        <property name="compile.lib.dir" value="${basedir}/lib"/>
        <property name="test.lib.dir" value="${basedir}/testlib"/>
        <property name="build.dir" value="${basedir}/bin"/>
        <property name="jboss.home" value="${env.JBOSS_HOME}"/>

       

        <fileset id="jboss-bootstrap-apis" dir="${jboss.home}/lib">
          <include name="jboss-bootstrap-api.jar"/>
          <include name="jboss-bootstrap-api-as.jar"/>
        </fileset>


        <fileset id="testlibs" dir="${test.lib.dir}">
          <include name="**/*.jar"/>
        </fileset>


        <path id="compile.classpath">
          <fileset dir="${compile.lib.dir}">
            <include name="**/*.jar"/>
          </fileset>
          <fileset refid="testlibs"/>
        </path>


        <path id="runtime.classpath">
          <!--fileset refid="testlibs"/ -->
          <fileset refid="jboss-bootstrap-apis"/>
          <fileset dir="${build.dir}"/>
          <fileset dir="${jboss.home}/lib"/>
          <fileset dir="${jboss.home}/lib/endorsed"/>
          <fileset dir="${jboss.home}/common/lib"/>
        </path>


        <patternset id="meta.files">
          <include name="**/*.xml"/>
          <include name="**/*.properties"/>
        </patternset>


        <target name="clean">
          <delete dir="${build.dir}"/>
          <mkdir dir="${build.dir}"/>
        </target>
       
        <target name="compile" depends="clean">
          <mkdir dir="${build.dir}"/>
          <javac
             srcdir="${src.java.dir}"
             destdir="${build.dir}"
             nowarn="on">
            <classpath refid="compile.classpath"/>
          </javac>
        </target>


        <target name="copymetafiles">
          <copy todir="${build.dir}">
            <fileset dir="${src.java.dir}">
          <patternset refid="meta.files"/>
            </fileset>
          </copy>
          <copy todir="${build.dir}">
            <fileset dir="${src.etc.dir}">
          <patternset refid="meta.files"/>
            </fileset>
          </copy>
        </target>


        <target name="run" depends="compile, copymetafiles" description="Build and run HelloWorld">
          <java fork="true"
            classname="hello.HelloWorld"
            classpathref="runtime.classpath">
            <classpath path="${build.dir}"/>
          </java>
        </target>
      </project>

       

      {code}

      package hello;


      import javax.naming.InitialContext;


      import org.jboss.bootstrap.api.lifecycle.LifecycleState;
      import org.jboss.bootstrap.api.lifecycle.LifecycleEventHandler;
      import org.jboss.bootstrap.api.lifecycle.LifecycleEventException;
      import org.jboss.embedded.api.server.JBossASEmbeddedServer;
      import org.jboss.embedded.api.server.JBossASEmbeddedServerFactory;
      import org.jboss.bootstrap.api.as.config.JBossASBasedServerConfig;


      public class HelloWorld {

          /** The server instance */
          private static JBossASEmbeddedServer server;

          /** JNDI Context */
          private static InitialContext initialContext;

          /** Server configuration name to use */
          private static final String NAME_SERVER_CONFIG = "standard";

          public static void dumpServerConfig(JBossASBasedServerConfig serverConfig) {
              System.out.println("Server config jboss Home: " + serverConfig.getJBossHome());
              System.out.println("Server config server name: " + serverConfig.getServerName());
              System.out.println("Server config bootstrap name: " + serverConfig.getBootstrapName());
              System.out.println("Server config server home location: " + serverConfig.getServerHomeLocation());
              System.out.println("Server config bootstrap Home: " + serverConfig.getBootstrapHome());
              System.out.println("Server config bootstrap URL: " + serverConfig.getBootstrapUrl());
              System.out.println("Server config server config location: " + serverConfig.getServerConfLocation());
              System.out.println("Server config server data location: " + serverConfig.getServerDataLocation());
              System.out.println("Server config server log location: " + serverConfig.getServerLogLocation());
              System.out.println("Server config server lib location: " + serverConfig.getServerLibLocation());
              System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
              System.out.println();
          }

          public static void main(String[] args)
                  throws Exception {

              final long initTime = System.currentTimeMillis();

              // Create the Server (will pull JBOSS_HOME from env var or sys prop)
              server = JBossASEmbeddedServerFactory.createServer();

              System.out.println("Created: \"" + server + "\" in " + (System.currentTimeMillis() - initTime) + " milliseconds.");


              final JBossASBasedServerConfig serverConfig = server.getConfiguration();

              serverConfig.serverName(NAME_SERVER_CONFIG);

              System.out.println("Configured: \"" + server + "\" in " + (System.currentTimeMillis() - initTime) + " milliseconds.");

              server.registerEventHandler(
                  new LifecycleEventHandler() {
                      public void handleEvent(LifecycleState state) throws LifecycleEventException {
                          System.out.println();
                          System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                          System.out.println("Current state is: " + state);
                          dumpServerConfig(server.getConfiguration());
                      }
                  },
                  LifecycleState.IDLE,
                  LifecycleState.INITIALIZED,
                  LifecycleState.INSTANCIATED,
                  LifecycleState.PRE_INIT,
                  LifecycleState.STARTED,
                  LifecycleState.STARTING,
                  LifecycleState.STOPPED,
                  LifecycleState.STOPPING);

              System.out.println();
              System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
              System.out.println("About to start the server, current state is: " + server.getState() +
                                 " at " + (System.currentTimeMillis() - initTime) + " milliseconds.");
              dumpServerConfig(server.getConfiguration());

              // Start the Server
              server.start();

              System.out.println("Started: \"" + server + "\" in " + (System.currentTimeMillis() - initTime) + " milliseconds.");

              // Set Naming Context
              initialContext = new InitialContext();


              while (server != null && !server.getState().equals(LifecycleState.STARTED)) {
                  System.out.println("Waiting to shut down server, current state is: " + server.getState());
              }

              // Shutdown if started
              if (server != null) {
                  // Shutdown
                  System.out.println("Shutting down server: \"" + server + "\"");
                  server.shutdown();
              }
              else {
                  System.out.println("No server to shut down.");
              }

          }
      }

      {code}

       

      Here is the output:

      {noformat}

      E:\Users\th1\Workspaces\test>E:\viewstore\jboss_dvl6.0\javatools\ant\bin\ant run
      Buildfile: build.xml

      clean:
         [delete] Deleting directory E:\Users\th1\Workspaces\test\bin
          [mkdir] Created dir: E:\Users\th1\Workspaces\test\bin

      compile:
          [javac] Compiling 1 source file to E:\Users\th1\Workspaces\test\bin

      copymetafiles:

      run:
           [java] Boot Log available in: C:\Users\th1\AppData\Local\Temp\
           [java] log4j:WARN No appenders could be found for logger (org.jboss.bootstrap.impl.base.server.AbstractServer).
           [java] log4j:WARN Please initialize the log4j system properly.
           [java] Created: "JBossAS [6.0.0.Final "Neo"]" in 39390 milliseconds.
           [java] Configured: "JBossAS [6.0.0.Final "Neo"]" in 39390 milliseconds.

           [java] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
           [java] About to start the server, current state is: INSTANCIATED at 39393 milliseconds.
           [java] Server config jboss Home: null
           [java] Server config server name: standard
           [java] Server config bootstrap name: null
           [java] Server config server home location: null
           [java] Server config bootstrap Home: null
           [java] Server config bootstrap URL: null
           [java] Server config server config location: null
           [java] Server config server data location: null
           [java] Server config server log location: null
           [java] Server config server lib location: null
           [java] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


           [java] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
           [java] Current state is: PRE_INIT
           [java] Server config jboss Home: null
           [java] Server config server name: standard
           [java] Server config bootstrap name: null
           [java] Server config server home location: null
           [java] Server config bootstrap Home: null
           [java] Server config bootstrap URL: null
           [java] Server config server config location: null
           [java] Server config server data location: null
           [java] Server config server log location: null
           [java] Server config server lib location: null
           [java] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


           [java] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
           [java] Current state is: INITIALIZED
           [java] Server config jboss Home: file:/C:/Applications/JBoss/jboss-6.0.0.Final/
           [java] Server config server name: standard
           [java] Server config bootstrap name: bootstrap.xml
           [java] Server config server home location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/
           [java] Server config bootstrap Home: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/conf/
           [java] Server config bootstrap URL: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/conf/bootstrap.xml
           [java] Server config server config location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/conf/
           [java] Server config server data location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/data/
           [java] Server config server log location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/log/
           [java] Server config server lib location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/lib/
           [java] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


           [java] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
           [java] Current state is: IDLE
           [java] Server config jboss Home: file:/C:/Applications/JBoss/jboss-6.0.0.Final/
           [java] Server config server name: standard
           [java] Server config bootstrap name: bootstrap.xml
           [java] Server config server home location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/
           [java] Server config bootstrap Home: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/conf/
           [java] Server config bootstrap URL: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/conf/bootstrap.xml
           [java] Server config server config location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/conf/
           [java] Server config server data location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/data/
           [java] Server config server log location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/log/
           [java] Server config server lib location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/lib/
           [java] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


           [java] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
           [java] Current state is: STARTING
           [java] Server config jboss Home: file:/C:/Applications/JBoss/jboss-6.0.0.Final/
           [java] Server config server name: standard
           [java] Server config bootstrap name: bootstrap.xml
           [java] Server config server home location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/
           [java] Server config bootstrap Home: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/conf/
           [java] Server config bootstrap URL: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/conf/bootstrap.xml
           [java] Server config server config location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/conf/
           [java] Server config server data location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/data/
           [java] Server config server log location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/log/
           [java] Server config server lib location: file:/C:/Applications/JBoss/jboss-6.0.0.Final/server/standard/lib/
           [java] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

      {noformat}

       

      and it just hangs there... I should see a line like:

       

      {noformat}

      [java] Started: "JBossAS [6.0.0.Final "Neo"]" in 139399 milliseconds

      {noformat}

       

      followed by shutdown information, but it never comes. Any ideas would be appreciated.

       

      Message was edited by: Tim Haley

        • 1. Re: Running Embedded JBoss via ANT with AS 6.0.0.Final
          ymaraner

          Ok, so I figured out how to configure log4j to give me some output and it appears that I have some classpath issues causing deployments to fail. I can work through those, although it would be nice if there were some documentation somewhere that indicated what JBoss jar files were needed on the classpath when using JBoss Embedded AS and whether or not the server lib directories are automatically added to the classpath.

           

          What really doesn't make any sense is that there is no boot log where the console output said it would be (C:\Users\th1\AppData\Local\Temp) and there are also no logs in the log directory under the server folder.

           

          Also, once all of the deployments fail, shouldn't the server move to the STARTED state and the output from my LifeCycleEventHandler indicate that it happened?

           

          Is this as designed? Is the server state supposed to stay at STARTING when deployments fail?