java.lang.NoClassDefFoundError: groovy/lang/GroovyObject

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25793068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:08:29  来源:igfitidea点击:

java.lang.NoClassDefFoundError: groovy/lang/GroovyObject

javaweb-servicesgroovyjunit

提问by J.Olufsen

Getting error when trying to test Jersey web services

尝试测试 Jersey 网络服务时出错

java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovyObject

.

.

import static com.jayway.restassured.RestAssured.expect;
import static com.jayway.restassured.RestAssured.get;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;

import org.junit.Test;

public class SimpleTest  {

    @Test
    public void testUserFetchesSuccess() {
        expect().
                body("id", equalTo("1")).
                when().
                get("/service");
    }


}

What does it mean? How to fix it?

这是什么意思?如何解决?

UPDATE

更新

I downloaded and installed groovy-all. Now I am getting:

我下载并安装了 groovy-all。现在我得到:

java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/typehandling/ShortTypeHandling
    at com.jayway.restassured.internal.ResponseParserRegistrar.<init>(ResponseParserRegistrar.groovy)
    at com.jayway.restassured.RestAssured.<clinit>(RestAssured.java:346)
    at SimpleTest.testUserFetchesSuccess(SimpleTest.java:10)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access
<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>2.4.5</version>
</dependency>
0(ParentRunner.java:50) at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.junit.runner.JUnitCore.run(JUnitCore.java:157) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63) Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.typehandling.ShortTypeHandling at java.net.URLClassLoader.run(URLClassLoader.java:366) at java.net.URLClassLoader.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 24 more

采纳答案by Jens

Download the groovy-all.jarand add it to the classpath.

下载groovy-all.jar并将其添加到类路径中。

With Maven, add this to your dependencies (browse groovy-all on mvnrepository.com):

使用 Maven,将其添加到您的依赖项(在 mvnrepository.com 上浏览 groovy-all):

##代码##

回答by Thunder

Perhaps you need to define the runner with an annotation above your class?

也许您需要在类上方使用注释定义跑步者?

In my case it's @RunWith(SerenityRunner.class)

就我而言,它是 @RunWith(SerenityRunner.class)

回答by Manoj Lonar

I was facing the same issue and surprisingly I was working with RestAssured. I struggled for the entire day to get this fixed.

我遇到了同样的问题,令人惊讶的是我正在与 RestAssured 合作。我整日都在努力解决这个问题。

I updated maven's groovy-all (version 3.0.0-beta-1) dependency with the latest one and this worked absolutely fine and I had added this dependency on the top in pom.xml. Hope this will help some folks :)

我用最新的更新了 maven 的 groovy-all(版本 3.0.0-beta-1)依赖项,这工作得很好,我在 pom.xml 的顶部添加了这个依赖项。希望这会帮助一些人:)

回答by saradhi

go to ireports and select tools and then options ->ireport ->select lanaguage as java

转到 ireports 并选择工具,然后选项 -> ireport -> 选择语言为 java