4 Replies Latest reply: May 15, 2012 2:25 PM by rajivtmathew RSS

Resolving dependencies for ShrinkWrap archive

rajivtmathew Newbie

I've been trying, for about a week now, to get arquillian setup working with Gradle build (which, I must say, is not the easiest thing in the world). I've finally reached the point where I've declared all dependencies in my build.gradle, and it now allows me to run tests using arquillian. When I try  to create a WebArchive for deployment as below:

 

 

@Deployment

    @TargetsContainer("jbossas-7")

    public static WebArchive createDeployment() {

        return ShrinkWrap.create(WebArchive.class, "archive.jar")

                .addClass(InitialContext.class)

                .addClass(RemoteRunner.class)

                .addClass(Runner.class)

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

    }

 

 

I keep running into NoClassDefFound errors, because of unresolved imports/dependencies of these classes. Is there a straightforward way of declaring dependent classes that must be included in the deployment, without having to hand-pick each one and declare it in the method above? I did notice a ShrinkWrap Maven resolver library, but was wondering if anything similar exists for projects built using Gradle.

  • 1. Re: Resolving dependencies for ShrinkWrap archive
    Jakub Narloch Novice

    Hi,

     

    I'm not entirely sure whether this is the problem in your case, but providing that you had pasted the actual code from your test, you are most likely getting this error due to using the ".jar" extension as the name of web archive. This issue has been described here: https://community.jboss.org/wiki/WhenIRunMyArquillianTestIGetAClassNotFoundExceptionForTheUnitTestClassItsSelfHowIsThatPossible.

     

    Hope it helps.

  • 2. Re: Resolving dependencies for ShrinkWrap archive
    rajivtmathew Newbie

    Thanks for the response Jakub. That change seemed to help execution proceed, although when my test did eventually run, I got this exception:

     

    java.lang.IllegalStateException: Cannot obtain MBeanServerConnection to: service:jmx:rmi:///jndi/rmi://127.0.0.1:1090/jmxrmi

        at org.jboss.as.arquillian.container.MBeanServerConnectionProvider.getConnection(MBeanServerConnectionProvider.java:64)

        at org.jboss.as.arquillian.container.remote.RemoteDeployableContainer.getMBeanServerConnection(RemoteDeployableContainer.java:66)

        at org.jboss.as.arquillian.container.remote.RemoteDeployableContainer.startInternal(RemoteDeployableContainer.java:52)

        at org.jboss.as.arquillian.container.CommonDeployableContainer.start(CommonDeployableContainer.java:88)

        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$5.perform(ContainerLifecycleController.java:144)

        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$5.perform(ContainerLifecycleController.java:134)

        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.forContainer(ContainerLifecycleController.java:182)

        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.startContainer(ContainerLifecycleController.java:133)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

        at org.jboss.arquillian.container.impl.client.ContainerDeploymentContextHandler.createContainerContext(ContainerDeploymentContextHandler.java:57)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)

        at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)

        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$2.perform(ContainerLifecycleController.java:83)

        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$2.perform(ContainerLifecycleController.java:76)

        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.forEachContainer(ContainerLifecycleController.java:175)

        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.startContainers(ContainerLifecycleController.java:75)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)

        at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)

        at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:83)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

        at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)

        at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeSuite(EventTestRunnerAdaptor.java:68)

        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:76)

        at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:51)

        at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:63)

        at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)

        at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)

        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)

        at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)

        at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:75)

        at $Proxy2.processTestClass(Unknown Source)

        at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:91)

        at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)

        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)

        at org.gradle.messaging.remote.internal.TypeCastDispatch.dispatch(TypeCastDispatch.java:30)

        at org.gradle.messaging.remote.internal.WorkerProtocol.handleIncoming(WorkerProtocol.java:53)

        at org.gradle.messaging.remote.internal.WorkerProtocol.handleIncoming(WorkerProtocol.java:31)

        at org.gradle.messaging.remote.internal.ProtocolStack$ProtocolStage.handleIncoming(ProtocolStack.java:167)

        at org.gradle.messaging.remote.internal.ProtocolStack$BottomStage.handleIncoming(ProtocolStack.java:277)

        at org.gradle.messaging.remote.internal.ProtocolStack$BottomConnection$1.run(ProtocolStack.java:299)

        at org.gradle.messaging.remote.internal.ProtocolStack$ExecuteRunnable.dispatch(ProtocolStack.java:120)

        at org.gradle.messaging.remote.internal.ProtocolStack$ExecuteRunnable.dispatch(ProtocolStack.java:116)

        at org.gradle.messaging.dispatch.AsyncDispatch.dispatchMessages(AsyncDispatch.java:132)

        at org.gradle.messaging.dispatch.AsyncDispatch.access$000(AsyncDispatch.java:33)

        at org.gradle.messaging.dispatch.AsyncDispatch$1.run(AsyncDispatch.java:72)

        at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)

        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

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

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

    Caused by: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:

        java.net.ConnectException: Connection refused: connect]

        at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:338)

        at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)

        at org.jboss.as.arquillian.container.MBeanServerConnectionProvider.getConnection(MBeanServerConnectionProvider.java:60)

        ... 89 more

    Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:

        java.net.ConnectException: Connection refused: connect]

        at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101)

        at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)

        at javax.naming.InitialContext.lookup(InitialContext.java:392)

        at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1886)

        at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)

        at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:255)

        ... 91 more

    Caused by: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:

        java.net.ConnectException: Connection refused: connect

        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)

        at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)

        at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)

        at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)

        at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)

        at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:97)

        ... 96 more

    Caused by: java.net.ConnectException: Connection refused: connect

        at java.net.PlainSocketImpl.socketConnect(Native Method)

        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)

        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)

        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)

        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)

        at java.net.Socket.connect(Socket.java:529)

        at java.net.Socket.connect(Socket.java:478)

        at java.net.Socket.<init>(Socket.java:375)

        at java.net.Socket.<init>(Socket.java:189)

        at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)

        at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)

        at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)

        ... 101 more

     

     

    My arquillian.xml file looks like this:

     

    <?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="jbossas-remote-7" default="true">

            <!--<protocol type="jmx-as7">-->

                <!--<property name="executionType">EMBEDDED</property>-->

            <!--</protocol>-->

            <protocol type="Servlet 3.0">

                <property name="executionType">MANAGED</property>

            </protocol>

            <configuration>

                <property name="startupTimeoutInSeconds">180</property>

                <property name="jbossHome">C:\jboss-as-7.1.1.Final\</property>

                <property name="managementAddress">127.0.0.1</property>

                <property name="managementPort">9999</property>

                <property name="javaVmArguments">-Xmx512m -XX:MaxPermSize=128m -Xrunjdwp:transport=dt_socket,address=8086,server=y,suspend=n</property>

                <property name="allowConnectingToRunningServer">true</property>

            </configuration>

        </container>

    </arquillian>

     

     

    I am running JBoss 7.1.1 server in a separate command prompt, (so the unit test can connect to that instance) and can verify that it is up and running. However, on the command prompt window running JBoss, when this test is executing, I see the following lines:

     

    11:48:46,062 ERROR [org.jboss.remoting.remote.connection] (Remoting "bel1-203261a:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host

    11:48:46,062 ERROR [org.jboss.remoting.remote.connection] (Remoting "bel1-203261a:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host

    11:48:46,062 ERROR [org.jboss.remoting.remote.connection] (Remoting "bel1-203261a:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host

    11:48:46,062 ERROR [org.jboss.remoting.remote.connection] (Remoting "bel1-203261a:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host

    11:48:46,078 ERROR [org.jboss.remoting.remote.connection] (Remoting "bel1-203261a:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host

    11:48:46,078 ERROR [org.jboss.remoting.remote.connection] (Remoting "bel1-203261a:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host

    11:48:46,078 ERROR [org.jboss.remoting.remote.connection] (Remoting "bel1-203261a:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host

    11:48:46,078 ERROR [org.jboss.remoting.remote.connection] (Remoting "bel1-203261a:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host

     

     

    Any ideas what could be causing this?Any help would be appreciated.

  • 3. Re: Resolving dependencies for ShrinkWrap archive
    Jakub Narloch Novice

    If You are running the JBoss AS in seperate JVM what You actually doing is trying to run the tests in remote container, so the settings that You had used may be irrevelant. I would suggest to try running the tests with config similar to this one:

     

     

    <?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">
    
        <defaultProtocol type="Servlet 3.0"/>
    
        <container qualifier="jbossas-remote-7" default="true">
            <configuration>
                <property name="jbossHome">C:\jboss-as-7.1.1.Final</property>
            </configuration>
        </container>
    </arquillian>
    
    

     

     

    Something similar works for me.

     

    Make sure that You have in the dependencies the correct version of jboss-as-arquillian-container-remote, that is exacly identical with the version of the server.

     

    Additionaly check if You have fallowing artifact in the dependencies:

     

     

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

     

  • 4. Re: Resolving dependencies for ShrinkWrap archive
    rajivtmathew Newbie

    Thanks for the follow-up. I'm still running into some dependency issues. I'm running arquillian against JBoss 7.1.1.Final.

    Project is built using gradle. Here are my dependencies:

     


    arquillian = [group: 'org.jboss.arquillian', name: 'arquillian-parent', version: '1.0.0.CR5']

    arquilliancore = [group: 'org.jboss.arquillian.core', name: 'arquillian-core-api', version: '1.0.0.CR5']

    arquilliancontainertest = [group: 'org.jboss.arquillian.container', name: 'arquillian-container-test-impl-base', version: '1.0.0.CR5']

    arquilliancontainerremote = [group: 'org.jboss.as', name: 'jboss-as-arquillian-container-remote', version: '7.1.1.Final']

    arquilliantest = [group: 'org.jboss.arquillian.test', name: 'arquillian-test-impl-base', version: '1.0.0.CR6']

    arquilliantestapi = [group: 'org.jboss.arquillian.container', name: 'arquillian-container-test-api', version: '1.0.0.CR5']

    arquillianspi = [group: 'org.jboss.arquillian.container', name: 'arquillian-container-spi', version: '1.0.0.CR5']

    arquillianjunit = [group: 'org.jboss.arquillian.junit', name: 'arquillian-junit-core', version: '1.0.0.CR5']

    arquillianservlet = [group: 'org.jboss.arquillian.protocol', name: 'arquillian-protocol-servlet', version: '1.0.0.Alpha3']

     

    Are you also running on JBoss 7.x? If so, it would be helpful if you could list your arquillian dependency tree, so I could compare.