Arquillian:Could not setup GlassFish Embedded Runtime

2.7k Views Asked by At

I try to make a test with Arquillian in a maven project however in every execution of the test that gives me the following exception:

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

This is the 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>

this is the 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>    

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

There are 2 best solutions below

4
KayDK On

There are many issues with your files that I can see without even trying your code. Many of the necessary steps and configurations are missing from your files.

  1. You do not have the the reference to the arquillian container from your pom.xml

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>                       
        <configuration>
            <systemPropertyVariables>                               
                <arquillian.launch>glassfish-embedded</arquillian.launch>
            </systemPropertyVariables>
        </configuration>
    </plugin>
    
  2. You should make sure that the glassfish container properties are correctly specified in the arquillian.xml. Example:

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

    You can get the full list of properties at https://docs.jboss.org/author/display/ARQ/GlassFish+3.1+-+Embedded

  3. Pay particular attention to whether you specify glassfish-resources.xml or domain.xml in the resourcesXml attrbiute. Generally, you can have the glassfish-resources.xml bundled within the application war.

I suggest you refer to:

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

i removed the block of code :

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

And i think that it solved the problem but now i have an other error message :

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