首页 > 解决方案 > 找不到参数的方法 jaxws() [com.sun.xml.ws:jaxws-tools:2.1.4]

问题描述

我正在尝试使用以下代码生成 java 类,但由于某些gradle插件问题而失败。

我搜索了它,发现有很多插件可用于生成 java 类,xsd但只有少数插件可用于生成plugins代码表单wsdljaxb是我想使用的其中之一。

这是我的 build.gradle 文件:

configurations {
    jaxws
}
buildscript {
    ext {
        springBootVersion = "2.1.4.RELEASE"
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
        jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

repositories {
    mavenCentral()
} 

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-actuator'
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.springframework.boot:spring-boot-starter-web-services'     
    compile 'org.apache.httpcomponents:httpclient'
    compile 'com.sun.xml.ws:jaxws-tools:2.1.4'
} 

task wsimport {
    ext.destDir = file("${projectDir}/src/main/generated")
    doLast {
        ant {
            sourceSets.main.output.classesDir.mkdirs()
            destDir.mkdirs()
            taskdef(name: 'wsimport',
                    classname: 'com.sun.tools.ws.ant.WsImport',
                    classpath: configurations.jaxws.asPath
            )
            wsimport(keep: true,
                    destdir: sourceSets.main.output.classesDir,
                    sourcedestdir: destDir,
                    extension: "true",
                    verbose: "false",
                    quiet: "false",
                    package: "com.abc.test",
                    xnocompile: "true",
                    wsdl: '${projectDir}/src/main/resources/wsdls/wsdl_1.0.0.wsdl') {
                xjcarg(value: "-XautoNameResolution")
            }
        }
    }
}

compileJava {
    dependsOn wsimport
    source wsimport.destDir
}
bootJar {
    baseName = 'API'
    version = '1.0'

}

现在这是我尝试使用命令行构建项目时遇到的错误。

C:\DEV\workspace\API>gradlew clean build --stacktrace

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\DEV\workspace\API\build.gradle' line: 14

* What went wrong:
A problem occurred evaluating root project 'API'.
> Could not find method jaxws() for arguments [com.sun.xml.ws:jaxws-tools:2.1.4] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. 

参考此代码; https://gist.github.com/ae6rt/8883335

标签: javagradlejaxbgradle-pluginwsimport

解决方案


configurations {
    jaxws
}

buildscript {
    dependencies {
        jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
    }
}

该配置jaxws不适用于构建脚本依赖项。首先,它被放置在buildscript配置之外,因此不可见。其次,构建脚本依赖只允许classpath配置(构建脚本的外部依赖)。jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'从构建脚本依赖项中删除修复问题

找不到参数的方法 jaxws() [...]

下一个问题是您将 jax-ws 依赖项定义为

compile 'com.sun.xml.ws:jaxws-tools:2.1.4'

并尝试将其引用为

taskdef(name: 'wsimport',
        classname: 'com.sun.tools.ws.ant.WsImport',
        classpath: configurations.jaxws.asPath)
                                  ^^^^^

jaxws到目前为止,配置没有定义依赖项,因此路径为空。将相关依赖项更改为

jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'

很可能会为您解决此问题。


更新

由于 Gradle 替换File classesDirFileCollection classesDirs,根据您的评论,您现在收到错误

方法没有签名:org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection.mkdirs() 适用于参数类型:() 值:[] 可能的解决方案:min()、tails()、first()、inits (), 减号(org.gradle.api.file.FileCollection), min(java.util.Comparator)

在线的

sourceSets.main.output.classesDirs.mkdirs()

如果您只有 1 个类输出目录,解决方法是使用

sourceSets.main.output.classesDirs.singleFile.mkdirs()

(来自:FileCollection.getSingleFile()


推荐阅读