0

我正在尝试使用 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>

然而我有一个错误:

无法在项目 testrunner 上执行目标 org.jboss.as.plugins:jboss-as-maven-plugin:7.4.Final:add-resource (add-datasource):无法执行目标添加资源。原因:I/O 错误无法执行操作 '{ "address" => [], "operation" => "read-attribute", "name" => "launch-type" }': java.net.ConnectException: JBAS012144:无法连接到远程://本地主机:9999。连接超时

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

任何帮助是极大的赞赏

提前致谢

4

1 回答 1

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>
于 2013-10-24T12:32:57.437 回答