使用Glassfish的Arquillian,resourcesXml属性似乎不是有效的文件路径

时间:2014-11-23 18:38:31

标签: java maven netbeans glassfish-4 jboss-arquillian

目标是使用Glassfish服务器运行Arquillian测试,但会发生以下错误:

java.lang.RuntimeException: The resourcesXml property does not appear to be 
a valid file path.

有谁看到这里缺少什么?

这就是Netbeans项目大纲的样子:

enter image description here

Netbeans中的文件夹结构如下所示:

enter image description here

这是arguillian.xml档案的内容:

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="
            http://jboss.org/schema/arquillian
            http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
    <container qualifier="glassfish-embedded" default="true">
        <configuration>
            <property name="resourcesXml">
                src/test/resources-glassfish-embedded/glassfish-resources.xml
            </property>
        </configuration>
    </container>
</arquillian>

这是glassfish-resources.xml档案的内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 
Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool allow-non-component-callers="false"
                      ...
                      wrap-jdbc-objects="false">
    <property name="serverName" value="localhost"/>
    <property name="portNumber" value="3306"/>
    <property name="databaseName" value="myappdatabase"/>
    <property name="User" value="someusername"/>
    <property name="Password" value="somepassword"/>
    <property name="URL" value="jdbc:mysql://localhost:3306/somedatabase"/>
    <property name="driverClass" value="com.mysql.jdbc.Driver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="jdbc/somedatabase" 
object-type="user" pool-name="jdbc/somedatabase_pool"/>
</resources>

感谢大家的耐心等待。

4 个答案:

答案 0 :(得分:1)

限定符必须是&#34; glassfish&#34;,这是一个完整的例子,它是如何为我工作的

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
 <engine>
    <property name="deploymentExportPath">target/arquillian</property>
 </engine> 
 <container default="true" qualifier="glassfish">
    <configuration>
        <property name="resourcesXml">src/test/resources-glassfish-embedded/glassfish-resources.xml</property>
        <property name="bindHttpPort">8083</property>
    </configuration>
 </container>
</arquillian>

答案 1 :(得分:1)

我遇到了同样的问题,似乎只接受了绝对路径。我通过资源过滤解决了它(类似于Slim的答案):

<强>的pom.xml

<testResources>
     <testResource>
         <directory>src/test/resources</directory>
         <filtering>true</filtering>
    </testResource>
</testResources>        

<强> arquillian.xml

<property name="resourcesXml">
    ${basedir}/src/test/resources/glassfish-resources.xml
</property>

答案 2 :(得分:0)

您可以在pom.xml中创建一个变量:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${version.maven-surefire-plugin}</version>
    <configuration>
        <systemPropertyVariables>
            <arquillianResourcesXml>
                ${project.basedir}/src/test/resources/resources-glassfish-embedded/glassfish-resources.xml
            </arquillianResourcesXml>
        </systemPropertyVariables>
    </configuration>
</plugin>

并在arquillian.xml文件中:

<property name="resourcesXml">${arquillianResourcesXml}</property>

为我工作。

答案 3 :(得分:0)

通过查看maven的控制台日志,我能够找出resourcesXml属性的正确值。有一条线说:

  

[INFO]跳过不存在的resourceDirectory   ... \ SRC \测试\资源-的glassfish包埋

检查文件系统上是否存在此文件夹。在我的情况下,我必须在resourcesXML值中添加一个额外的资源,如:

src/test/resources/resources-glassfish-embedded/glassfish-resources.xml