当我从 SpringBoot2.7.6 和 java 17 切换到 SpringBoot 3.1.1 时,我遇到了 Spring Boot 的 javax.xml.bind.JAXBException 的 ClassNotFoundException(java 17 是相同的)。
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at org.apache.cxf.tools.wsdlto.WSDLToJava.<init>(WSDLToJava.java:48)
at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:181)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 2 more
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':accountAdjustmentService'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
下面是build.gradle
group 'my.com.pkg'
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: "io.spring.dependency-management"
apply plugin: 'io.mateo.cxf-codegen'
apply plugin: "org.owasp.dependencycheck"
//apply plugin: "io.snyk.gradle.plugin.snykplugin"
archivesBaseName = "my-app-service"
// Set java version independent of host JAVA_HOME
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
compile {
extendsFrom implementation
}
}
buildscript {
ext {
springBootVersion = "3.1.1"
springCloudVersion = "2022.0.3"
dependencyManagementPluginVersion = "1.1.0"
springdocVersion = "1.7.0"
mockserverVersion = "5.15.0"
//wsdl2java
cxfCodegenGradleVersion = "1.2.1"
apacheCxfVersion = "4.0.0" //"3.3.2"
jaxb2BasicsVersion = "1.11.1"
jaxbWsImplVersion = "4.0.0"
jwsApiVersion = "3.0.0"
jakartaAnnotationApiVersion = "1.3.5"
}
repositories {
maven {
url "https://my.artifactory.com/artifactory/repo"
metadataSources {
mavenPom()
artifact()
ignoreGradleMetadataRedirection()
}
}
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:$dependencyManagementPluginVersion"
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
classpath 'org.owasp:dependency-check-gradle:8.2.1'
classpath "io.mateo:cxf-codegen-gradle:$cxfCodegenGradleVersion"
// classpath "javax.xml.bind:jaxb-api:2.3.1"
}
}
repositories {
maven {
url "https://my.artifactory.com/artifactory/repo"
metadataSources {
mavenPom()
artifact()
ignoreGradleMetadataRedirection()
}
}
}
import io.mateo.cxf.codegen.wsdl2java.Wsdl2Java
import org.gradle.internal.logging.text.StyledTextOutputFactory
import static org.gradle.internal.logging.text.StyledTextOutput.Style
bootRun {
sourceResources sourceSets.main
// systemProperty 'logging.config', 'src/main/resources/logback-local.xml'
}
//colored output borrowed from https://github.com/biasedbit/gradle-plugins/blob/master/colored-test-output.gradle
System.setProperty('org.gradle.color.failure', 'RED')
System.setProperty('org.gradle.color.progressstatus', 'YELLOW')
System.setProperty('org.gradle.color.success', 'GREEN')
dependencies {
annotationProcessor("org.projectlombok:lombok")
compileOnly("org.projectlombok:lombok")
implementation(
"org.springframework.boot:spring-boot-starter-parent:$springBootVersion",
"org.springframework.boot:spring-boot-starter-web",
"org.springframework.boot:spring-boot-configuration-processor",
"org.springframework.boot:spring-boot-starter-validation",
"org.springframework.boot:spring-boot-starter-actuator",
"org.springframework.boot:spring-boot-starter-jdbc",
"org.springframework.cloud:spring-cloud-starter-parent:$springCloudVersion",
"org.springframework.cloud:spring-cloud-starter-bootstrap",
"org.springframework.cloud:spring-cloud-starter-config",
"org.springdoc:springdoc-openapi-ui:$springdocVersion",
"com.oracle.database.jdbc:ojdbc8",
"javax.validation:validation-api"
)
// implementation("javax.xml.bind:jaxb-api:2.3.1")
// implementation("javax.activation:activation:1.1")
//extra libs for javax,xml.bind exception
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0'
implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.0'
// enable soap calls to WebMethods services
implementation ('org.springframework.boot:spring-boot-starter-web-services') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
exclude group: 'com.github.java-json-tools', module: 'json-schema-core'
}
implementation 'org.springframework.ws:spring-ws-core'
// Runtime dependencies for the generated code
implementation "org.jvnet.jaxb2_commons:jaxb2-basics-runtime:$jaxb2BasicsVersion"
implementation "org.apache.cxf.xjc-utils:cxf-xjc-runtime:$apacheCxfVersion"
// implementation "jakarta.jws:jakarta.jws-api:$jwsApiVersion "
implementation "com.sun.xml.bind:jaxb-impl:$jaxbWsImplVersion"
implementation ("com.sun.xml.ws:jaxws-ri:$jaxbWsImplVersion"){
exclude group: 'com.fasterxml.woodstox', model: 'woodstox'
}
// ciscoo cxf codegen
// For wsdl2java generating toString(), equals(), and hashcode() with xjc args
cxfCodegen "org.apache.cxf.xjcplugins:cxf-xjc-ts:$apacheCxfVersion"
cxfCodegen("org.jvnet.jaxb2_commons:jaxb2-basics:$jaxb2BasicsVersion") {
exclude group: 'commons-beanutils', module: 'commons-beanutils'
}
// Other dependencies needed for code generation
cxfCodegen "jakarta.xml.ws:jakarta.xml.ws-api:$jaxbWsImplVersion"
cxfCodegen "jakarta.annotation:jakarta.annotation-api:$jakartaAnnotationApiVersion"
// end ciscoo cxf codegen
testImplementation(
"org.springframework.boot:spring-boot-starter-test:$springBootVersion",
// Using older JUnit4 rather than current JUnit5
"org.junit.vintage:junit-vintage-engine",
"io.rest-assured:rest-assured",
// "io.rest-assured:json-schema-validator",
"io.rest-assured:json-path",
"org.mock-server:mockserver-integration-testing:$mockserverVersion",
"org.mock-server:mockserver-junit-rule:$mockserverVersion",
"org.mock-server:mockserver-netty:$mockserverVersion"
)
testImplementation("org.mock-server:mockserver-integration-testing:$mockserverVersion"){
exclude group: 'io.swagger.parser.v3', module: 'swagger-parser'
}
testImplementation("io.rest-assured:json-schema-validator"){
exclude group: 'org.mozilla', module: 'rhino'
}
testImplementation "org.projectlombok:lombok"
testAnnotationProcessor "org.projectlombok:lombok"
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
task listAllDependencies(type: DependencyReportTask) {}
// ciscoo cxf codegen
tasks.register("myOfferWsdl", Wsdl2Java) {
toolOptions {
wsdl.set(file("$projectDir/src/main/resources/wsdl/MyOfferWsdl-v1.wsdl"))
serviceName.set("MyOfferWsdl_v1_0")
outputDir.set(file("$buildDir/generated"))
markGenerated.set(true)
bindingFiles.add(layout.projectDirectory.file("$projectDir/src/main/resources/wsdl/binding.xjb").asFile.absolutePath)
xjcArgs.add("-Xts")
xjcArgs.add("-Xequals")
xjcArgs.add("-XhashCode")
}
}
tasks.register("myAccountWsdl", Wsdl2Java) {
toolOptions {
wsdl.set(file("$projectDir/src/main/resources/wsdl/MyAccountWsdl-v1.wsdl"))
serviceName.set("MyAccountWsdl_v1_0")
outputDir.set(file("$buildDir/generated"))
markGenerated.set(true)
// bindingFiles.add(layout.projectDirectory.file("$projectDir/src/main/resources/wsdl/binding.xjb").asFile.absolutePath)
xjcArgs.add("-Xts")
xjcArgs.add("-Xequals")
xjcArgs.add("-XhashCode")
}
}
compileJava.dependsOn(wsdl2java)
test {
if (project.hasProperty('excludeTests')) {
exclude project.property('excludeTests')
}
testLogging {
exceptionFormat = 'full'
}
def out = services.get(StyledTextOutputFactory).create('colored-test-output')
out.style(Style.Normal)
beforeSuite { suite ->
if (suite.name.startsWith('Test Run') || suite.name.startsWith('Gradle Worker')) return
out.println("\n" + suite.name)
}
afterTest { descriptor, result ->
def style
if (result.failedTestCount > 0) style = Style.Failure
else if (result.skippedTestCount > 0) style = Style.ProgressStatus
else style = Style.Success
out.text(' ').withStyle(style).println(descriptor.name)
}
}
task jarWithSources(type: Jar, dependsOn: classes) {
// classifier = 'source'
from sourceSets.main.allSource
from sourceSets.main.output
}
task cloneLicenses(type: Exec) {
delete 'doc'
ignoreExitValue false
standardOutput = new ByteArrayOutputStream()
errorOutput = new ByteArrayOutputStream()
commandLine 'git', 'clone', 'https://my.gitlab.com/contracts/licenses.git', 'doc'
}
task startDockerDB(type: Exec) {
workingDir 'database/docker-oracle'
standardOutput = new ByteArrayOutputStream()
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
commandLine = ['cmd', '/C', 'start', 'run_docker.bat']
} else {
commandLine './run_docker.sh'
}
}
task shutDownDockerDB(type: Exec) {
workingDir 'database/docker-oracle'
standardOutput = new ByteArrayOutputStream()
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
commandLine = ['cmd', '/C', 'start', 'stop_docker.bat']
} else {
commandLine './stop_docker.sh'
}
}
jar {
enabled = false
}
defaultTasks 'clean', 'wsdl2java', 'startDockerDB', 'build', 'shutDownDockerDB'
我尝试寻找像下面这样的其他建议,但没有成功。
尝试明确如下
implementation("javax.xml.bind:jaxb-api:2.3.1")
implementation("javax.activation:activation:1.1")
添加了 jakarta 依赖项
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0'
implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.0'
我希望代码能够成功构建,因为它是使用 SpringBppt2.7.6(和 openjdk17.0.2)构建的
只是回顾一下代码的用途
SpringBoot 3.1.1
openjdk 17.0.2
gradle-wrapper: 8.0.2-all.zip
您好,我也面临同样的问题,您找到解决方案了吗?