java.lang.ClassNotFoundException:运行黄瓜功能时的sun.reflect.ConstantPool

时间:2019-11-08 06:03:45

标签: java eclipse cucumber

Using the 11.0.4 jdk in eclipse我正在使用eclipse运行黄瓜功能,但出现此错误。我已经安装了Java 11.0.4。

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by cucumber.runtime.java8.ConstantPoolTypeIntrospector (file:/Users/test1/.m2/repository/info/cukes/cucumber-java8/1.2.5/cucumber-java8-1.2.5.jar) to method java.lang.Class.getConstantPool()
WARNING: Please consider reporting this to the maintainers of cucumber.runtime.java8.ConstantPoolTypeIntrospector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread “main” cucumber.runtime.CucumberException: Failed to instantiate class test.sample.cucumber.steps.TestAPISteps
    at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:47)
    at cucumber.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:33)
    at cucumber.runtime.java.JavaBackend.buildWorld(JavaBackend.java:131)
    at cucumber.runtime.Runtime.buildBackendWorlds(Runtime.java:141)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:38)
    at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
    at cucumber.runtime.Runtime.run(Runtime.java:122)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:41)
    ... 8 more
Caused by: java.lang.NoClassDefFoundError: sun/reflect/ConstantPool
    at cucumber.runtime.java8.ConstantPoolTypeIntrospector.getGenericTypes(ConstantPoolTypeIntrospector.java:29)
    at cucumber.runtime.java.Java8StepDefinition.getParameterInfos(Java8StepDefinition.java:54)
    at cucumber.runtime.java.Java8StepDefinition.<init>(Java8StepDefinition.java:44)
    at cucumber.runtime.java.JavaBackend.addStepDefinition(JavaBackend.java:162)
    at cucumber.api.java8.En.Given(En.java:199)
    at com.cbre.host.foodandbeverages.cucumber.steps.ProductStoreApiSteps.<init>(ProductStoreApiSteps.java:40)
    ... 13 more
Caused by: java.lang.ClassNotFoundException: sun.reflect.ConstantPool
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 19 more

这可能是什么原因? 这仅在我的机器上发生。在其他计算机上,不会复制此问题。 我试图更新Maven项目。尝试并在STS上也遇到了同样的问题。

两台机器都安装了相同的Java。

java version "11.0.4" 2019-07-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.4+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.4+10-LTS, mixed mode)

2 个答案:

答案 0 :(得分:1)

您的其他计算机必须在java8上运行。您的错误跟踪建议使用java8。

WARNING: Please consider reporting this to the maintainers of cucumber.runtime.java8.ConstantPoolTypeIntrospector

答案 1 :(得分:1)

您当前正在使用Cucumber JVM 1.2.5。此版本的Cucumber不能在Java 9或更高版本上运行。您可能要考虑升级。

Cucumber JVM的最新发行版本是4.8.0。请注意,groupId已从info.cukes变为io.cucumber