Why the arquillian gives me that : Could not read

2019-09-01 16:51发布

问题:

I try to integrate the arquillian solution into my maven EJB project which contains juste the EJBs which I uses in other separate projects.

I use Jboss EAP6.

So i have make it as the following :

I made the arquillian.xml into ejbModule/src/test/resources/:

<container qualifier="jboss" default="true">
    <configuration>
        <property name="jbossHome">D:\jbdevstudio\jboss-eap-6.2</property>
    </configuration>
</container> 

in the pom of my project i added the following dependencies:

<dependency>
   <groupId>org.jboss.arquillian.container</groupId>
    <artifactId>arquillian-jbossas-embedded-6</artifactId>
   <version>1.0.0.Alpha5</version>
</dependency>

<dependency>
   <groupId>org.jboss.arquillian</groupId>
   <artifactId>arquillian-junit</artifactId>
   <version>1.0.0.Alpha5</version>
</dependency>

<dependency>
   <groupId>org.jboss.arquillian.junit</groupId>
   <artifactId>arquillian-junit-container</artifactId>
   <scope>test</scope>
</dependency>

<dependency>
   <groupId>org.jboss.arquillian.protocol</groupId>
   <artifactId>arquillian-protocol-servlet</artifactId>
  <scope>test</scope>
</dependency> 

<dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.8.2</version>
</dependency> 
<profiles>
   <profile>
        <id>jbossas-embedded-6</id>
        <activation>
        <activeByDefault>true</activeByDefault>
        </activation>
   </profile>

   <profile>
        <id>arq-jbossas-managed</id>
             <dependencies>
                  <dependency>
                       <groupId>org.jboss.as</groupId>
                       <artifactId>jboss-as-arquillian-containermanaged</artifactId>
                       <scope>test</scope>
                  </dependency>
             </dependencies>
   </profile>

   <profile>
        <id>arq-jbossas-remote</id>
        <dependencies>
             <dependency>
                  <groupId>org.jboss.as</groupId>
                  <artifactId>jboss-as-arquillian-containerremote</artifactId>
                  <scope>test</scope>
             </dependency>
        </dependencies>
   </profile>
</profiles>

The Test Class :

import javax.inject.Inject;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.oap.subscription.AbstractSubscription;

@RunWith(Arquillian.class)
    public class SubscriptionFactoryTest {   

    @Inject
    private SubscriptionFactory subscriptionFactory;

    @Deployment
    public static JavaArchive getDeployement() {
        System.out.println("### testSayHelloEJB");
        return ShrinkWrap.create(JavaArchive.class, "subscriptionFactory.jar")
            .addClasses(AbstractSubscription.class,SubscriptionFactory.class);

    }



    @Test
    public void getSubscriptionByIdTest() {
        System.out.println("### testSayHelloEJB");
    }
}

The EJB Class:

@Remote(ISubscriptionFactoryRemote.class)
@Local(ISubscriptionFactoryLocal.class)
@Stateless
public class SubscriptionFactory extends AbstractSubscription implements ISubscriptionFactoryRemote {

    @Override
    public AbstractSubscription getSubscriptionById(final Integer id) {

        AbstractSubscription ret = null;
        if (id != null) {
            // create query
            final StringBuilder queryString = new StringBuilder("select c from AbstractSubscription c ");           

            try {
                queryString.append("where c.id = :id");

                // create query
                Query query = this.getEntityManager().createQuery(queryString.toString());

                // set parameter
                query = query.setParameter("id", id);

                // recovers refCountry
                ret = (AbstractSubscription) query.getSingleResult();

            } catch (final Exception exc) {

            }

        }

        return ret;

    }
}

When i run the class test as Junit test , it gives me the errors :

 janv. 20, 2015 12:15:34 PM org.jboss.arquillian.impl.client.container.ContainerRegistryCreator getActivatedConfiguration
 Infos: Could not read active container configuration: null 

the Faillure Trace:

 java.lang.NoClassDefFoundError: Lorg/jboss/embedded/api/server/JBossASEmbeddedServer;
 at java.lang.Class.getDeclaredFields0(Native Method)
 at java.lang.Class.privateGetDeclaredFields(Class.java:2397)
 at java.lang.Class.getDeclaredFields(Class.java:1806)
 at org.jboss.arquillian.impl.core.Reflections.getFieldInjectionPoints(Reflections.java:74)
 ... 79 more

Any idea.

回答1:

You're using a very old version of Arquillian, I'd use at least version 1.1.0.Final. I also don't think you need a few of the Arquillian dependencies you have defined.

Remove the arquillian-jbossas-embedded-6 and arquillian-junit depdendencies.

There are plenty of quickstart examples of how to use Arquillian with JBoss EAP. Have a look at some of the pom's there as it might help.