Skip to content

OSGI class not found exception with Arquillian and JBoss AS7

Posted on:September 11, 2015

If you are using Arquillian with JBoss AS7.x and get the following exception:

Sep 11, 2015 3:17:04 AM org.jboss.arquillian.protocol.jmx.JMXMethodExecutor invoke
SEVERE: Failed: org.acme.YourClassTest.testMethod
java.lang.NoClassDefFoundError: org/jboss/as/osgi/deployment/OSGiDeploymentAttachment

You need to override the JBoss JMX invoker with the Arquillian version:

<!-- pom.xml -->
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.jboss.arquillian</groupId>
      <artifactId>arquillian-bom</artifactId>
      <version>1.1.9.Final</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
...
<dependencies>
  <dependency>
    <groupId>org.jboss.arquillian.protocol</groupId>
    <artifactId>arquillian-protocol-servlet</artifactId>
    <scope>test</scope>
  </dependency>
</dependencies>

And override servlet 3.0 in your test class using @OverProtocol:

class YourClassTest {
  @Deployment
  @OverProtocol("Servlet 3.0")
  public static JavaArchive createDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
        .addClasses(YourClass.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
  }
}