java.lang.noclassdeffounderror:io/restassured/path/xml/mapper/factory/jaxbobjectmapperfactory

e0bqpujr  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(627)

我在试着运行一个 Cucumber 测试用例场景,在中编译后收到错误 IntelliJ-IDEA . 我已经把那封信寄出去了 build.gradle 在这里归档。我不知道为什么我一运行程序就出现这个错误。有人能告诉我怎么解决这个问题吗?我发现这个错误已经一天多了,仍然没有解决方法。
堆栈跟踪错误

java.lang.NoClassDefFoundError: io/restassured/path/xml/mapper/factory/JAXBObjectMapperFactory
    at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
    at io.restassured.RestAssured.<clinit>(RestAssured.java:420)
    at AbtMainTestControl.PostJsonDetail.postJsonPayload(PostJsonDetail.java:17)
    at AbtMainTestControl.AbtCardPavTest.first_PAV_is_Transact(AbtCardPavTest.java:110)

Caused by: java.lang.ClassNotFoundException: io.restassured.path.xml.mapper.factory.JAXBObjectMapperFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
    at io.restassured.RestAssured.<clinit>(RestAssured.java:420)
    at AbtMainTestControl.PostJsonDetail.postJsonPayload(PostJsonDetail.java:17)
    at AbtMainTestControl.AbtCardPavTest.first_PAV_is_Transact(AbtCardPavTest.java:110)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at cucumber.runtime.Utils$1.call(Utils.java:26)
    at cucumber.runtime.Timeout.timeout(Timeout.java:16)
    at cucumber.runtime.Utils.invoke(Utils.java:20)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:57)
    at cucumber.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:50)
    at cucumber.runner.TestStep.executeStep(TestStep.java:65)
    at cucumber.runner.TestStep.run(TestStep.java:50)
    at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:43)
    at cucumber.runner.TestCase.run(TestCase.java:46)
    at cucumber.runner.Runner.runPickle(Runner.java:50)
    at cucumber.runtime.Runtime$1.run(Runtime.java:104)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at cucumber.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:258)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
    at cucumber.runtime.Runtime.run(Runtime.java:101)
    at io.cucumber.core.cli.Main.run(Main.java:43)
    at io.cucumber.core.cli.Main.main(Main.java:14)

java.lang.NoClassDefFoundError: Could not initialize class io.restassured.RestAssured
    at AbtMainTestControl.PostJsonDetail.postJsonPayload(PostJsonDetail.java:17)
    at AbtMainTestControl.AbtCardPavTest.first_PAV_is_Transact(AbtCardPavTest.java:110)
    at ✽.First PAV is 

java.lang.NoClassDefFoundError: io/restassured/path/xml/mapper/factory/JAXBObjectMapperFactory
    at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
    at io.restassured.RestAssured.<clinit>(RestAssured.java:420)
    at AbtMainTestControl.PostJsonDetail.postJsonPayload(PostJsonDetail.java:17)
    at AbtMainTestControl.AbtCardPavTest.first_PAV_is_Transact(AbtCardPavTest.java:110)
    at ✽.First PAV is Transact(file:/C:/Users/lukegoh/Documents/GitHub/AbtMainTestControl/AbtMainTestControl/src/test/resources/features/AbtCardPAVTest.feature:10)
Caused by: java.lang.ClassNotFoundException: io.restassured.path.xml.mapper.factory.JAXBObjectMapperFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
    at io.restassured.RestAssured.<clinit>(RestAssured.java:420)
    at AbtMainTestControl.PostJsonDetail.postJsonPayload(PostJsonDetail.java:17)
    at AbtMainTestControl.AbtCardPavTest.first_PAV_is_Transact(AbtCardPavTest.java:110)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at cucumber.runtime.Utils$1.call(Utils.java:26)
    at cucumber.runtime.Timeout.timeout(Timeout.java:16)
    at cucumber.runtime.Utils.invoke(Utils.java:20)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:57)
    at cucumber.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:50)
    at cucumber.runner.TestStep.executeStep(TestStep.java:65)
    at cucumber.runner.TestStep.run(TestStep.java:50)
    at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:43)
    at cucumber.runner.TestCase.run(TestCase.java:46)
    at cucumber.runner.Runner.runPickle(Runner.java:50)
    at cucumber.runtime.Runtime$1.run(Runtime.java:104)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at cucumber.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:258)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
    at cucumber.runtime.Runtime.run(Runtime.java:101)
    at io.cucumber.core.cli.Main.run(Main.java:43)
    at io.cucumber.core.cli.Main.main(Main.java:14)

java.lang.NoClassDefFoundError: Could not initialize class io.restassured.RestAssured
    at AbtMainTestControl.PostJsonDetail.postJsonPayload(PostJsonDetail.java:17)
    at AbtMainTestControl.AbtCardPavTest.first_PAV_is_Transact(AbtCardPavTest.java:110)
    at ✽.First PAV is Transact(file:/C:/Users/lukegoh/Documents/GitHub/AbtMainTestControl/AbtMainTestControl/src/test/resources/features/AbtCardPAVTest.feature:10)

Process finished with exit code 1

构建.gradle

plugins {
    id 'org.springframework.boot' version '2.3.4.RELEASE'
}

apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven-publish'

sourceCompatibility = 1.8
targetCompatibility = 1.8

group 'AbtMainTestControl'
version '1.0-SNAPSHOT'

// Versioning of dependencies
wrapper.gradleVersion = '6.6.1'
def cucumberVersion = '4.7.1'
def junitVersion = '5.5.0'
def restVersion = '4.1.2'
def apacheDrillVersion = '1.17.0'

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'
    compile group: 'com.opencsv', name: 'opencsv', version: '4.0'

    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.12'

    compile group: 'org.apache.drill.tools', name: 'tools-parent', version: "${apacheDrillVersion}", ext: 'pom'

    compile group: 'de.monochromata.cucumber', name: 'reporting-plugin', version: '3.0.9'

    testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.1.0.jre8'

    compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.7.0'

    compile 'org.modelmapper:modelmapper:2.3.3'

    implementation('org.springframework.boot:spring-boot-starter-web')
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')

    testImplementation "io.cucumber:cucumber-java:${cucumberVersion}"
    testImplementation "io.cucumber:cucumber-junit:${cucumberVersion}"
    testImplementation "io.rest-assured:rest-assured:${restVersion}"
    testImplementation "io.rest-assured:json-path:${restVersion}"
    testImplementation "io.rest-assured:json-schema-validator:${restVersion}"

    testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
    testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junitVersion}"
    implementation 'junit:junit:4.12'

    compileOnly 'org.projectlombok:lombok:1.18.12'
    annotationProcessor 'org.projectlombok:lombok:1.18.12'

    testCompileOnly 'org.projectlombok:lombok:1.18.12'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'

    implementation 'org.mapstruct:mapstruct:1.4.1.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.1.Final'

    compile group: 'org.hibernate', name: 'hibernate-gradle-plugin', version: '5.4.22.Final'
}

configurations {
    cucumberRuntime {
        extendsFrom testImplementation
    }
}

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "io.cucumber.core.cli.Main"
            classpath =  configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin',
                    'pretty',
                    '--glue',
                    'gradle.cucumber',
                    'src/test/resources/features',

            ]
        }
    }
}

test {
    //useJUnitPlatform()
    systemProperty "cucumber.options", System.properties.getProperty("cucumber.options")
}

注意:我已经删除了错误的冗余部分。

snvhrwxg

snvhrwxg1#

我设法解决了这个问题 java.lang.NoClassDefFoundError: io/restassured/path/xml/mapper/factory/JAXBObjectMapperFactory 显式声明 json-path 以及 xml-pathbuild.gradle 文件。
我是这样宣布的。
构建.gradle

plugins {
    id 'org.springframework.boot' version '2.3.4.RELEASE'
}

apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven-publish'

sourceCompatibility = 1.8
targetCompatibility = 1.8

group 'AbtMainTestControl'
version '1.0-SNAPSHOT'

// Versioning of dependencies
wrapper.gradleVersion = '6.6.1'
def cucumberVersion = '4.7.1'
def junitVersion = '5.5.0'
def restVersion = '4.1.2'
def apacheDrillVersion = '1.17.0'

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'
    compile group: 'com.opencsv', name: 'opencsv', version: '4.0'

    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.12'

    compile group: 'org.apache.drill.tools', name: 'tools-parent', version: "${apacheDrillVersion}", ext: 'pom'

    compile group: 'de.monochromata.cucumber', name: 'reporting-plugin', version: '3.0.9'

    testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.1.0.jre8'

    compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.7.0'

    compile 'org.modelmapper:modelmapper:2.3.3'

    implementation('org.springframework.boot:spring-boot-starter-web')
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')

    testImplementation "io.cucumber:cucumber-java:${cucumberVersion}"
    testImplementation "io.cucumber:cucumber-junit:${cucumberVersion}"
    testImplementation "io.rest-assured:rest-assured:${restVersion}"
    testImplementation "io.rest-assured:json-path:${restVersion}"
    testImplementation "io.rest-assured:xml-path:${restVersion}"
    testImplementation "io.rest-assured:json-schema-validator:${restVersion}"

    testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
    testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junitVersion}"
    implementation 'junit:junit:4.12'

    compileOnly 'org.projectlombok:lombok:1.18.12'
    annotationProcessor 'org.projectlombok:lombok:1.18.12'

    testCompileOnly 'org.projectlombok:lombok:1.18.12'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'

    implementation 'org.mapstruct:mapstruct:1.4.1.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.1.Final'

    compile group: 'org.hibernate', name: 'hibernate-gradle-plugin', version: '5.4.22.Final'
}

configurations {
    cucumberRuntime {
        extendsFrom testImplementation
    }
}

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "io.cucumber.core.cli.Main"
            classpath =  configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin',
                    'pretty',
                    '--glue',
                    'gradle.cucumber',
                    'src/test/resources/features',

            ]
        }
    }
}

test {
    //useJUnitPlatform()
    systemProperty "cucumber.options", System.properties.getProperty("cucumber.options")
}

重新发布的依赖项声明(续)

testImplementation "io.rest-assured:rest-assured:${restVersion}"
testImplementation "io.rest-assured:json-path:${restVersion}"
testImplementation "io.rest-assured:xml-path:${restVersion}"
testImplementation "io.rest-assured:json-schema-validator:${restVersion}"

其背后的原因可以在以下链接中找到:java.lang.noclassdeffounderror:io/restassured/mapper/factory/gsonobjectmapperfactory
对于那些懒得访问链接的人,以下是解释:
根本原因是*objectmapperfactory包名发生了变化,例如在3.x和4.x版本之间。
对于任何在rest assured 4.0.0发布后遇到这个问题的人来说,这个问题可能会出现在spring boot项目中,这是由于rest assured与其在spring boot dependencies bom中的json path和xml path的可传递依赖项之间的版本不匹配造成的。
如果指定依赖项io.rest-assured:rest-assured:4.0.0,还需要显式包含io.rest-assured:json-path:4.0.0和io.rest-assured:xml-path:4.0.0,否则spring引导依赖项将使用旧的*objectmapperfactory包名拉入版本3.1.1。

相关问题