Starting JBossAS automatically

Version 4

    You can run your tests against local JBossAS6* for example by starting server first and running tests against it afterwards. Arquillian detects, if server has been started. That's fast and fine for local testing. But sometimes you want to start container automatically.

     

    You might get an exception like this:

     

    {code}
    Caused by: org.jboss.arquillian.spi.DeploymentException: Could not deploy test.war
        at org.jboss.arquillian.jbossas.local60.JBossASLocalContainer.deploy(JBossASLocalContainer.java:150)
        at org.jboss.arquillian.impl.handler.ContainerDeployer.callback(ContainerDeployer.java:62)
        at org.jboss.arquillian.impl.handler.ContainerDeployer.callback(ContainerDeployer.java:50)
        at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:63)
        ... 18 more
    Caused by: javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]]
    {code}

     

    JBOSS_HOME and JAVA_HOME needs to be set, either as environment variables or arquillian.xml.

     

    I personally prefer setting JAVA_HOME by environment variable and jbossHome by specific arquillian.xml.

     

    example src/test/resources/arquillian.xml:

     

    {code:xml}

    <?xml version="1.0"?>

     

    <arquillian xmlns="http://jboss.com/arquillian"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:jboss="urn:arq:org.jboss.arquillian.jbossas.local60">

     

        <jboss:container>
            <jbossHome>target/jboss-6.0.0.20100429-M3</jbossHome>
            <!-- <javaHome>/usr/lib/jvm/java-6-openjdk</javaHome> Will default o JAVA_HOME-->
            <bindAddress>127.0.0.1</bindAddress>
            <httpPort>8080</httpPort> <!-- WARN: this is not the bind port, but connect port. Bind port must be set in jboss xml config -->
        </jboss:container>   

     

    </arquillian>

    {code}

     

    So from now, Arquillian will startup server, if no JBossAS is running already.