rest-assured / rest-assured

Java DSL for easy testing of REST services
Apache License 2.0
6.86k stars 1.88k forks source link

java.lang.NoClassDefFoundError: org/apache/commons/lang3/Validate #847

Open johno1985 opened 7 years ago

johno1985 commented 7 years ago

The following exception occurs when I tried running my first test using RestAssured version 3.0.2:

java.lang.NoClassDefFoundError: org/apache/commons/lang3/Validate at io.restassured.config.LogConfig.(LogConfig.java:86) at io.restassured.config.LogConfig.(LogConfig.java:45) at io.restassured.config.RestAssuredConfig.(RestAssuredConfig.java:41) at io.restassured.RestAssured.(RestAssured.java:420) at com.launchworks.launchbi.it.cognos.ReportDataIT.returnOK(ReportDataIT.java:11) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.Validate at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 28 more

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.2</version>
    <scope>test</scope>
</dependency>
package com.mycomp.myproduct.it;

import static io.restassured.RestAssured.get;

import org.junit.Test;

public class ReportDataIT {

    @Test
    public void returnOK() {
        get("localhost:8080/Report/data").then().assertThat().statusCode(200);
    }
}
johanhaleby commented 7 years ago

I think there's something wrong with your classpath. You most likely haven't imported all REST Assured dependencies. See getting started guide.

johno1985 commented 7 years ago

I have followed all instructions. There is no mention of explicitly importing any other dependencies

On 19 Apr 2017 05:37, "Johan Haleby" notifications@github.com wrote:

I think there's something wrong with your classpath. You most likely haven't imported all REST Assured dependencies. See getting started guide.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rest-assured/rest-assured/issues/847#issuecomment-295083924, or mute the thread https://github.com/notifications/unsubscribe-auth/ABkJATtT4YHtJV01Gv5itvtEY_vLoPA3ks5rxY-QgaJpZM4NAqT6 .

johanhaleby commented 7 years ago

What do you mean by importing? There are indeed instructions that you should download all dependencies and put them in your classpath.

johno1985 commented 7 years ago

I have done that, see the pin snippet above

On 19 Apr 2017 13:30, "Johan Haleby" notifications@github.com wrote:

What do you mean by importing? There are indeed instructions that you should download all dependencies and put them in your classpath.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rest-assured/rest-assured/issues/847#issuecomment-295251185, or mute the thread https://github.com/notifications/unsubscribe-auth/ABkJASjzick0efZZFJWnPTe4qS7qghA_ks5rxf5KgaJpZM4NAqT6 .

johanhaleby commented 7 years ago

Then there's something wrong with your maven configuration. You might be excluding commons-lang3 or it's overridden by some other transitive dependency. You could try to move rest-assured to the top of your libraries.

johno1985 commented 7 years ago

I don't believe that is the case, this is the output of my dependency graph:

io.rest-assured:rest-assured:jar:3.0.2:test [INFO] | +- org.codehaus.groovy:groovy:jar:2.4.6:test [INFO] | +- org.codehaus.groovy:groovy-xml:jar:2.4.6:test [INFO] | +- org.apache.httpcomponents:httpmime:jar:4.5.1:test [INFO] | +- org.hamcrest:hamcrest-core:jar:1.3:test [INFO] | +- org.hamcrest:hamcrest-library:jar:1.3:test [INFO] | +- org.ccil.cowan.tagsoup:tagsoup:jar:1.2.1:test [INFO] | +- io.rest-assured:json-path:jar:3.0.2:test [INFO] | | +- org.codehaus.groovy:groovy-json:jar:2.4.6:test [INFO] | | - io.rest-assured:rest-assured-common:jar:3.0.2:test [INFO] | - io.rest-assured:xml-path:jar:3.0.2:test [INFO] | - org.apache.commons:commons-lang3:jar:3.4:test [INFO] - junit:junit:jar:4.12:test

On 19 April 2017 at 14:21, Johan Haleby notifications@github.com wrote:

Then there's something wrong with your maven configuration. You might be excluding commons-lang3 or it's overridden by some other transitive dependency. You could try to move rest-assured to the top of your libraries.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rest-assured/rest-assured/issues/847#issuecomment-295267860, or mute the thread https://github.com/notifications/unsubscribe-auth/ABkJAaKdYNAeAzbcmoHCurbm2zEyf_xZks5rxgpYgaJpZM4NAqT6 .

johanhaleby commented 7 years ago

That's very weird since the class you're referring to is available in org.apache.commons:commons-lang3:jar:3.4

kobbikobb commented 5 years ago

I tried exactly the code above and it worked. This is very old and seems to be relevant to the setup of the machine.

Can we close this, can´t reproduce?

jawadk commented 5 years ago

As indicated on https://github.com/rest-assured/rest-assured/wiki/GettingStarted#java-9 you may add a dependency rest-assured-all.

<dependency>
   <groupId>io.rest-assured</groupId>
   <artifactId>rest-assured-all</artifactId>
   <version>4.0.0</version>
</dependency>

Add it SOLVED my problem.