Question

I'm trying to make work arquillian tests with jboss managed server and IBM DB2 database.

For now I'm stuck on creating datasource. Since JBoss is unpacked on each run, I'm trying to add driver and datasource configuration into pom.xml in order to Maven take care of creating proper configurations on JBoss and resulting section looks like this:

<profile>
    <id>arquillian-jboss-managed</id>
    <build>
        <plugins>
            <!-- JBoss server itself -->
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>process-test-classes</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.jboss.as</groupId>
                                    <artifactId>jboss-as-dist</artifactId>
                                    <version>7.1.1.Final</version>
                                    <type>zip</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>target</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- adding datasource -->           
            <plugin>
                <groupId>org.jboss.as.plugins</groupId>
                <artifactId>jboss-as-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>deploy-driver</id>
                        <phase>process-test-classes</phase>
                        <!-- groupId and artifactId aren't global, I've got jar on defined path  -->
                        <configuration>
                            <groupId>db2</groupId>
                            <artifactId>db2cc</artifactId>
                            <name>db2jcc4.jar</name>
                        </configuration>
                        <goals>
                            <goal>deploy-artifact</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>add-datasource</id>
                        <phase>process-test-resources</phase>
                        <configuration>
                            <address>subsystem=datasources,data-source=MyDataSource</address>
                            <properties>
                                <connection-url>jdbc:db2://host:port/database</connection-url>
                                <jndi-name>MyDataSource</jndi-name>
                                <enabled>true</enabled>
                                <pool-name>MyDataSource</pool-name>
                                <user-name>db2inst1</user-name>
                                <password>pass</password>
                                <driver-name>db2jcc4.jar</driver-name>
                            </properties>
                        </configuration>
                        <goals>
                            <goal>add-resource</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</profile>

Yet I've got an error:

Failed to execute goal org.jboss.as.plugins:jboss-as-maven-plugin:7.4.Final:add-resource (add-datasource) on project testrunner: Could not execute goal add-resource. Reason: I/O Error could not execute operation '{ "address" => [], "operation" => "read-attribute", "name" => "launch-type" }': java.net.ConnectException: JBAS012144: Could not connect to remote://localhost:9999. The connection timed out

I guess the problem is JBoss isn't started at the moment Maven tries to apply configuration parameters or simply doesn't listen to required port.

Any help is greatly appreciated

Thanks in advance

Was it helpful?

Solution

Fixing this problem was as simple as adding start and shutdown goals to jboss-as-maven-plugin executions before and after other configuration:

<execution>
    <id>start-server</id>
    <phase>process-test-classes</phase>                                
    <goals>
        <goal>start</goal>
    </goals>
</execution>
<!-- copying driver and datasource here -->
<execution>
    <id>shutdown-server</id>
    <phase>process-test-classes</phase>                                
    <goals>
        <goal>shutdown</goal>
    </goals>
</execution>

Also this start goal downloads it's own JBoss instance if one is not provided. So this part is not needed any more:

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <!-- skipped -->
</plugin>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top