1 Reply Latest reply on Feb 24, 2017 1:46 AM by Matous Jobanek

    NoClassDefFoundError: Failed to link

    tim nguyen Newbie

      Hi All,

       

      I'm new to Arquillian, I followed the "Getting Started" and it went very smoothly. But when I try to run a simple unit-test with arquillian on my current project, it is giving me an error that it cannot link to the class (AuthenticationCommand). The test is a simple assert true just to see if i'm able to run arquillian. The hystrix is in a jar and set as a maven dependency.

       

      AuthenticationCommandTest.java

      import javax.inject.Inject;

      import org.jboss.arquillian.container.test.api.Deployment;

      import org.jboss.arquillian.junit.Arquillian;

      import org.jboss.shrinkwrap.api.ShrinkWrap;

      import org.jboss.shrinkwrap.api.spec.JavaArchive;

      import org.jboss.shrinkwrap.api.asset.EmptyAsset;

      import org.junit.Assert;

      import org.junit.Test;

      import org.junit.runner.RunWith;

      import static org.junit.Assert.*;

      import static org.hamcrest.core.Is.*;

       

       

      @RunWith(Arquillian.class)

      public class AuthenticationCommandTest {

       

        @Inject

        private AuthenticationCommand authenticationCommand;

       

        @Deployment

        public static JavaArchive createDeployment() {

        return ShrinkWrap.create(JavaArchive.class)

        .addClass(AuthenticationCommand.class)

        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

        }

       

        @Test

        public void should_be_deployed() {

        Assert.assertNotNull(authenticationCommand);

        Assert.assertTrue(true);

        }

      }

      AuthenticationCommand.java

      import java.nio.charset.Charset;

      import java.security.AccessControlException;

      import java.util.Base64;

      import org.slf4j.Logger;

      import org.slf4j.LoggerFactory;

      import com.netflix.hystrix.HystrixCommand;

      import com.netflix.hystrix.HystrixCommandGroupKey;

       

      public class AuthenticationCommand extends HystrixCommand<String> {

        private static Logger log = LoggerFactory.getLogger(AuthenticationCommand.class);

          public static final String COMMAND_NAME = "GetToken";

          private String userCredentials;

       

           public AuthenticationCommand(String userCredentials){

              super(HystrixCommandGroupKey.Factory.asKey(COMMAND_NAME));

              this.userCredentials = userCredentials;

          }

       

          @Override

          protected String run() throws Exception {

              if (isValid(userCredentials)) {

                  return "";

              }

              throw new AccessControlException("Not Authorized");

          }

       

          @Override

          protected String getFallback() {

              return null;

          }

       

          public boolean isValid(String userCredentials) {

              if (userCredentials != null && userCredentials.startsWith("Basic"))

                  return true; //TODO: implement logic to check if the credentials match the database and return a token

              }

              return false;

          }

      arquillian.xml

      <?xml version="1.0" encoding="UTF-8" standalone="no"?>

      <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 default="true" qualifier="arquillian-wildfly-managed">

          <configuration>

            <property name="chameleonTarget">wildfly:10.1.0.Final:MANAGED</property>

          </configuration>

        </container>

      </arquillian>

       

      pom.xml

      <profiles>

          <profile>

            <id>arquillian-wildfly-managed</id>

            <activation>

              <activeByDefault>true</activeByDefault>

            </activation>

            <build>

              <plugins>

                <plugin>

                  <artifactId>maven-surefire-plugin</artifactId>

                  <version>2.14.1</version>

                  <configuration>

                    <systemPropertyVariables>

                      <arquillian.launch>arquillian-wildfly-managed</arquillian.launch>

                      <chameleon.target>wildfly:10.1.0.Final:MANAGED</chameleon.target>

                    </systemPropertyVariables>

                  </configuration>

                </plugin>

              </plugins>

            </build>

          </profile>

        </profiles>

      <dependencyManagement>

        <dependencies>

        <dependency>

             <groupId>org.jboss.arquillian</groupId>

             <artifactId>arquillian-bom</artifactId>

             <version>${version.arquillian}</version>

             <scope>import</scope>

             <type>pom</type>

           </dependency>

           <dependency>

         <groupId>org.jboss.shrinkwrap</groupId>

         <artifactId>shrinkwrap-bom</artifactId>

         <version>1.2.6</version>

         <type>pom</type>

         <scope>import</scope>

        </dependency>

        </dependencies>

        </dependencyManagement>

      <dependencies>

      <dependency>

            <groupId>org.arquillian.universe</groupId>

            <artifactId>arquillian-junit</artifactId>

            <type>pom</type>

            <scope>test</scope>

           </dependency>

        <dependency>

            <groupId>org.arquillian.universe</groupId>

            <artifactId>arquillian-chameleon</artifactId>

            <type>pom</type>

            <scope>test</scope>

           </dependency>

                  <dependency>

                  <groupId>org.jboss.arquillian.junit</groupId>

                  <artifactId>arquillian-junit-container</artifactId>

                  <scope>test</scope>

              </dependency>

              <dependency>

           <groupId>org.jboss.shrinkwrap</groupId>

           <artifactId>shrinkwrap-depchain</artifactId>

           <type>pom</type>

           <scope>test</scope>

        </dependency>

        </dependencies>

       

      Failure Trace

      java.lang.NoClassDefFoundError: Failed to link com/core/auth/AuthenticationCommand (Module "deployment.test.war:main" from Service Module Loader): com/netflix/hystrix/HystrixCommand

        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

        at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:446)

        at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:274)

        at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:78)

        at org.jboss.modules.Module.loadModuleClass(Module.java:606)

        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)

        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)

        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)

        at java.lang.Class.getDeclaredFields0(Native Method)

        at java.lang.Class.privateGetDeclaredFields(Class.java:2583)

        at java.lang.Class.getDeclaredFields(Class.java:1916)

        at org.junit.runners.model.TestClass.getSortedDeclaredFields(TestClass.java:77)

        at org.junit.runners.model.TestClass.scanAnnotatedMembers(TestClass.java:70)

        at org.junit.runners.model.TestClass.<init>(TestClass.java:57)

        at org.junit.runners.ParentRunner.createTestClass(ParentRunner.java:88)

        at org.junit.runners.ParentRunner.<init>(ParentRunner.java:83)

        at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)

        at org.jboss.arquillian.junit.Arquillian.<init>(Arquillian.java:61)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

        at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)

        at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)

        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)

        at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)

        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)

        at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)

        at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)

        at org.junit.runner.JUnitCore.run(JUnitCore.java:115)

        at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:66)

        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:170)

        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:135)

        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:98)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

        at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)

        at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

        at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

        at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

        at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)

        at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

        at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

        at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

        at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)

        at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)

        at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)

        at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

        at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

        at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)

        at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)

        at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)

        at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)

        at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)

        at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)

        at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

        at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

        at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

        at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

        at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

        at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)

        at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)

        at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)

        at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)

        at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

        at java.lang.Thread.run(Thread.java:745)

       

       

      Thank you in advance for your time!

        • 1. Re: NoClassDefFoundError: Failed to link
          Matous Jobanek Novice

          Hi,

          looking at the stacktrace - not sure what the "PathToAuthenticationCommand" stands for...?

          Anyway, the problem is probably because you are missing the class "com/netflix/hystrix/HystrixCommand"  on the container side (where the test is run). To run the AuthenticationCommand.java class in a container you need to have all necessary libraries available there. This can be done by adding the libraries into the deployment.