Arquillian:无法设置GlassFish Embedded Runtime

时间:2015-04-29 11:21:49

标签: junit glassfish junit4 jboss-arquillian glassfish-embedded

我尝试在maven项目中使用Arquillian进行测试,但是在每次执行测试时都会出现以下异常:

Grave: Exception in command execution : java.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.855 sec <<< FAILURE!
Tests in error: 
es.costa.service.test.magali.PersonaFactorTest: Could not setup GlassFish Embedded Runtime
Caused by: org.glassfish.embeddable.GlassFishException: PlainTextActionReporterFAILUREjava.lang.NoClassDefFoundError: javax/validation/ParameterNameProviderjava.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider
java.lang.RuntimeException: Could not setup GlassFish Embedded Runtime

这是pom.xml:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <artifactId>arquillian-bom</artifactId>
            <version>1.0.3.Final</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.jboss.ejb3</groupId>
        <artifactId>jboss-ejb3-ext-api</artifactId>
        <version>2.1.0</version>
    </dependency>
    <dependency>
        <groupId>es.costa</groupId>
        <artifactId>costa-interfaces</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.1.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <version>5.0.3.Final</version>
    </dependency>
</dependencies>
<build>
    <sourceDirectory>ejbModule/src/main/java</sourceDirectory>
    <testSourceDirectory>ejbModule/src/test/java</testSourceDirectory>
    <resources>
        <resource>
            <directory>ejbModule/src/main/resources</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>ejbModule/src/test/resources</directory>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <encoding>Cp1252</encoding>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12</version>
        </plugin>
        <plugin>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>${maven-ejb-plugin.version}</version>
            <configuration>
                <ejbVersion>${ejb.version}</ejbVersion>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <artifactSet>
                    <includes>
                        <include>es.costa</include>
                    </includes>
                </artifactSet>
                <finalName>${artifactId}-${project.version}</finalName>
            </configuration>
        </plugin>


        <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <configuration>
                <filename>${artifactId}-${project.version}.jar</filename>
            </configuration>
        </plugin>
    </plugins>
</build>
<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <dependencies>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>persistence-api</artifactId>
                <version>${javax-persistance.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>jenkins</id>
        <dependencies>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>persistence-api</artifactId>
                <version>${javax-persistance.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>arquillian-glassfish-embedded</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian.container</groupId>
                <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
                <version>1.0.0.CR3</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.glassfish.main.extras</groupId>
                <artifactId>glassfish-embedded-all</artifactId>
                <version>3.1.2</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <version>1.3.166</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <testResources>
                <testResource>
                    <directory>ejbModule/src/test/resources</directory>
                </testResource>
                <testResource>
                    <directory>ejbModule/src/test/resources-glassfish-embedded</directory>
                </testResource>
            </testResources>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.12</version>
                    <configuration>
                        <systemPropertyVariables>
                           <arquillian.launch>glassfish-embedded</arquillian.launch>
                            <java.util.logging.config.file>
                                ${project.build.testOutputDirectory}/logging.properties
                            </java.util.logging.config.file>
                            <derby.stream.error.file>
                                ${project.build.directory}/derby.log
                            </derby.stream.error.file>
                        </systemPropertyVariables>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

这是arquillian.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">
            ejbModule/src/test/resources-glassfish-embedded/glassfish-resources.xml
        </property>
    </configuration>
</container>    

这是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-resource pool-name="ArquillianEmbeddedH2Pool"
    jndi-name="jdbc/arquillian"/>
<jdbc-connection-pool name="ArquillianEmbeddedH2Pool"
    res-type="javax.sql.DataSource"
    datasource-classname="org.h2.jdbcx.JdbcDataSource">
    <property name="user" value="sa"/>
    <property name="password" value=""/>
    <property name="url" value="jdbc:h2:file:target/databases/h2/db"/>
</jdbc-connection-pool>    

2 个答案:

答案 0 :(得分:0)

您的文件存在许多问题,我甚至无需尝试您的代码即可看到。您的文件中缺少许多必要的步骤和配置。

  1. 您没有pom.xml

    对arquillian容器的引用
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>                       
        <configuration>
            <systemPropertyVariables>                               
                <arquillian.launch>glassfish-embedded</arquillian.launch>
            </systemPropertyVariables>
        </configuration>
    </plugin>
    
  2. 您应该确保在arquillian.xml中正确指定了glassfish容器属性。例如:

    <property name="resourcesXml">src/test/resources/domain.xml</property>
    <property name="glassFishHome">${glassfish.managed.home}</property>
    

    您可以在https://docs.jboss.org/author/display/ARQ/GlassFish+3.1+-+Embedded

  3. 获取完整的媒体资源列表
  4. 要特别注意您是否在glassfish-resources.xml attrbiute中指定domain.xmlresourcesXml。通常,您可以在应用程序战争中捆绑glassfish-resources.xml

  5. 我建议你参考:

    1. https://github.com/arquillian/arquillian-examples
    2. http://arquillian.org/guides/getting_started/

答案 1 :(得分:0)

我删除了代码块:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.1.3.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator-annotation-processor</artifactId>
    <version>5.0.3.Final</version>
</dependency>

我认为它解决了问题,但现在我还有其他错误信息:

ArquillianServletRunner not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.