2

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.

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. But I can't use these classes in "Service Client" (seems like Idea can't see them).

Here is my 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

Alt + Enter offers to create new class, and import leads to this: img.techpowerup.org/200624/2344.jpg

I will be very grateful for any help.

Dest
  • 31
  • 1
  • 3
  • Does `Alt`+`Enter` help you to import the lass? Have you tried to type `import com.example.consumingwebservice.wsdl.Author;`? – Nikolas Charalambidis Jun 24 '20 at 12:10
  • Alt + Enter offers to create class "Author", and import leads to this: https://img.techpowerup.org/200624/2344.jpg – Dest Jun 24 '20 at 12:29
  • Try to right-click to the `jaxb` generated folder and select `Mark Directory as` and select `Generated Sources Root` (a blue folder). – Nikolas Charalambidis Jun 24 '20 at 12:38
  • You should not use IDE functionality to resolve problems with your build tool, as it should be independent from IDE settings. Instead check out how to add generated sources to the compilation done by Gradle (e.g. [here](https://stackoverflow.com/questions/28345705/how-can-i-add-a-generated-source-folder-to-my-source-path-in-gradle)). – Lukas Körfer Jun 24 '20 at 13:12
  • You could also just use one of the many xjc plugins that does all these things for you. – Bjørn Vester Jun 25 '20 at 08:31

1 Answers1

3

This is also the problem with Maven users. So for Maven users, the solution is very simple

  1. Right-click the project folder
  2. Select Maven
  3. Select Generate Sources And Update Folders

Then, Intellij automatically imports generated sources to the project.

Fot Gradle users, the process might be the same.