如何使用Maven为JBoss插件设置数据源以使用Arquillian运行测试?

时间:2013-10-23 14:10:41

标签: maven jboss jboss-arquillian

我正在尝试使用jboss托管服务器和IBM DB2数据库进行arquillian测试。

现在我一直坚持创建数据源。由于JBoss在每次运行时都被解压缩,我正在尝试将驱动程序和数据源配置添加到pom.xml中,以便Maven负责在JBoss上创建正确的配置,结果部分如下所示:

<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>

但我有一个错误:

  

无法执行目标   org.jboss.as.plugins:的jboss-AS-Maven的插件:7.4.Final:新增资源   项目testrunner上的(add-datasource):无法执行目标   增加资源。原因:I / O错误无法执行操作'{   “地址”=&gt; [],“操作”=&gt; “read-attribute”,“name”=&gt;   “launch-type”}':java.net.ConnectException:JBAS012144:无法   连接到remote:// localhost:9999。连接超时

我想问题是,当Maven尝试应用配置参数或者根本不听所需的端口时,JBoss没有启动。

非常感谢任何帮助

提前致谢

1 个答案:

答案 0 :(得分:1)

修复此问题就像在其他配置之前和之后为jboss-as-maven-plugin执行添加启动和关闭目标一样简单:

<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>

此开始目标也会下载自己的JBoss实例(如果没有提供)。所以这部分不再需要了:

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <!-- skipped -->
</plugin>