gpt4 book ai didi

gradle - jar打包后带有Boot的Spring-WS不起作用

转载 作者:行者123 更新时间:2023-12-03 06:04:21 29 4
gpt4 key购买 nike

我的项目分为几个模块:

包含实际 Web 服务的子模块。

依赖子模块并定义自己的@SpringBootApplication 类的几个模块:

version '1.0'

apply plugin: 'java'
apply plugin: 'spring-boot'

sourceCompatibility = 1.8

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}

repositories {
mavenCentral()
}

dependencies {
compile project(':submodule')
}

jar {
baseName = 'jarfilename'
}

现在的问题是,运行 jar 文件时无法访问由子模块的 JAXB 任务生成的类:
javax.xml.bind.JAXBException: "bws.wsdl" doesnt contain ObjectFactory.class or jaxb.index
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:266) ~[na:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:171) ~[na:1.8.0_91]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:131) ~[na:1.8.0_91]
... 31 common frames omitted

该项目在 IDE (Intellij Idea) 上运行良好。

子模块的 build.gradle 如下所示:
version '1.0'

apply plugin: 'java'

sourceCompatibility = 1.8

configurations {
jaxb
}

repositories {
mavenCentral()
}

// tag::wsdl[]
task genJaxb {
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
ext.classesDir = "${buildDir}/classes/jaxb"
ext.schema = "path-to-wsdl.xml"
outputs.dir classesDir

doLast() {
project.ant {
taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
classpath: configurations.jaxb.asPath
mkdir(dir: sourcesDir)
mkdir(dir: classesDir)

xjc(destdir: sourcesDir, schema: schema,
package: "wsdl") {
arg(value: "-wsdl")
produces(dir: sourcesDir, includes: "**/*.java")
}

javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
debugLevel: "lines,vars,source",
classpath: configurations.jaxb.asPath) {
src(path: sourcesDir)
include(name: "**/*.java")
include(name: "*.java")
}

copy(todir: classesDir) {
fileset(dir: sourcesDir, erroronmissingdir: false) {
exclude(name: "**/*.java")
}
}
}
}
}

dependencies {
compile(files(genJaxb.classesDir).builtBy(genJaxb))

jaxb "com.sun.xml.bind:jaxb-xjc:2.1.7"
}

task afterEclipseImport {
dependsOn genJaxb
}

最佳答案

原来我只是忘记包含生成的类:

jar {
baseName = 'jarfilename'
from "${rootDir}/submodule/build/classes/jaxb"
}

关于gradle - jar打包后带有Boot的Spring-WS不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39616996/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com