繁体   English   中英

无法通过 IntelliJ Idea 和 Gradle 使用构建文件夹中生成的类

[英]Can't use generated classes from build folder with IntelliJ Idea and Gradle

I'm trying to follow this guide (consuming a SOAP web service) with IntelliJ Idea and Gradle - https://spring.io/guides/gs/consuming-web-service/#initial

我已经有了 SOAP 服务器,它工作正常,我可以在我的本地主机上看到我的 WSDL。

我重复了指南中的每一步,但是当谈到“创建 [...] 服务客户端”时,我遇到了一些问题。 我确实有一个名为“generated-sources”的文件夹,它包含我的类,从 WSDL 生成。 但我不能在“服务客户端”中使用这些类(好像 Idea 看不到它们)。

这是我的build.gradle

plugins {
    id 'org.springframework.boot' version '2.2.0.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    jaxb
}

repositories {
    mavenCentral()
}

task genJaxb {
    ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
    ext.classesDir = "${buildDir}/classes/jaxb"
    ext.schema = "http://localhost:8080/ws/author.wsdl"

    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: "com.example.consumingwebservice.wsdl") {
                arg(value: "-wsdl")
                produces(dir: sourcesDir, includes: "**/*.java")
            }

            javac(destdir: classesDir, source: 11, target: 11, 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 {

    implementation ('org.springframework.boot:spring-boot-starter-web-services') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
    }
    implementation 'org.springframework.ws:spring-ws-core'
    // For Java 11:
    implementation 'org.glassfish.jaxb:jaxb-runtime'
    compile(files(genJaxb.classesDir).builtBy(genJaxb))

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

    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

bootJar {
    baseName = 'gs-consuming-web-service'
    version =  '0.0.1'
}

这是我的截图- https://img.techpowerup.org/200624/2687.jpg

Alt + Enter 提供创建新的 class,并导入导致此:img.techpowerup.org/200624/2344.jpg

我将非常感谢任何帮助。

这也是Maven用户的问题。 所以对于Maven用户来说,解决方法很简单

  1. 右键单击项目文件夹
  2. Select Maven
  3. Select生成源和更新文件夹

然后,Intellij 会自动将生成的源导入到项目中。

Fot Gradle 用户,过程可能相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM