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

标签 java spring-boot gradle intellij-idea soap

我正在尝试使用 IntelliJ IdeaGradle 遵循本指南(使用 SOAP Web 服务) - 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 提供创建新类的功能,导入后会显示:img.techpowerup.org/200624/2344.jpg

我将非常感谢任何帮助。

最佳答案

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

  1. 右键单击项目文件夹
  2. 选择Maven
  3. 选择生成源并更新文件夹

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

对于 Gradle 用户,过程可能是相同的。

关于java - 无法通过 IntelliJ Idea 和 Gradle 使用构建文件夹中生成的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62554688/

相关文章:

java - 内存不足错误 : Java heap space gradle compiling android

javascript - Windows 中的 "~/.gradle"文件夹在哪里?

java - 如何更改 RecyclerView 中单个项目的颜色?

java - Intellij IDEA 无法解决 Gradle 依赖关系

spring - 将自定义 SecurityExpressionOperations 中的方法注册为 Spring SpEL 函数

java - 如何将嵌套 JSON 数组转换为 java 对象?

android - 原因 : com. android.dex.DexException : Multiple dex files define Lorg/apache/commons/io/IOCase in Studio 3. 0

java - 如何计算格式为 TimeDuration 的时间差

java - NeighboringCellInfo、CID 和 LAC 的空问题

java - 我如何替换java中的字符串来重写序列