简体   繁体   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 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

I already have SOAP-server, it's working fine and I can see my WSDL on my localhost.我已经有了 SOAP 服务器,它工作正常,我可以在我的本地主机上看到我的 WSDL。

I repeated every step in the guide, but when it comes to "Create a [...] Service Client" I ran into some problems.我重复了指南中的每一步,但是当谈到“创建 [...] 服务客户端”时,我遇到了一些问题。 I do have a folder named "generated-sources" and it contains my classes, generated from WSDL.我确实有一个名为“generated-sources”的文件夹,它包含我的类,从 WSDL 生成。 But I can't use these classes in "Service Client" (seems like Idea can't see them).但我不能在“服务客户端”中使用这些类(好像 Idea 看不到它们)。

Here is my build.gradle :这是我的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'
}

And this is my screenshot - https://img.techpowerup.org/200624/2687.jpg这是我的截图- https://img.techpowerup.org/200624/2687.jpg

Alt + Enter offers to create new class, and import leads to this: img.techpowerup.org/200624/2344.jpg Alt + Enter 提供创建新的 class,并导入导致此:img.techpowerup.org/200624/2344.jpg

I will be very grateful for any help.我将非常感谢任何帮助。

This is also the problem with Maven users.这也是Maven用户的问题。 So for Maven users, the solution is very simple所以对于Maven用户来说,解决方法很简单

  1. Right-click the project folder右键单击项目文件夹
  2. Select Maven Select Maven
  3. Select Generate Sources And Update Folders Select生成源和更新文件夹

Then, Intellij automatically imports generated sources to the project.然后,Intellij 会自动将生成的源导入到项目中。

Fot Gradle users, the process might be the same. Fot Gradle 用户,过程可能相同。

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

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