如何超越Gradle wsimport任务JDK 8的访问限制?

10

我在我的Gradle构建中有一个wsimport任务,直到Java 7都可以正常工作:

task wsimport {
    ext.destDir = file("${buildDir}/generated/java")
    ext.wsdlSrc = file("src/main/resources/schema/example/my.wsdl")
    ext.bindingSrc = file("src/main/resources/schema/example/bindings.xsd")
    outputs.dir destDir
    doLast {
        ant {
            destDir.mkdirs()
            taskdef(name: 'wsimport',
                classname: 'com.sun.tools.ws.ant.WsImport',
                classpath: configurations.jaxws.asPath)
            wsimport(keep: true,
                package: 'net.example.my',
                xnocompile: true,
                quiet: true,
                sourcedestdir: destDir,
                wsdl: wsdlSrc,
                binding: bindingSrc,
                encoding: "UTF-8"
            )
        }
    }
}

切换到JDK 8(版本1.8.0-b129)时,我遇到了以下错误:
java.lang.AssertionError: org.xml.sax.SAXParseException; systemId: ... schema_reference:
Failed to read schema document 'xjc.xsd', because 'file' access is not allowed due to restriction set by the accessExternalSchema property.

我在查找问题时发现了以下帖子(令人惊讶的是,它还描述了Java 7中的问题):https://github.com/stianh/gradle-jaxb-plugin/issues/20但是我无法将环境/参数传递给wsimport/xjc。

如何禁用此访问或限制?

1个回答

7
我找到的唯一有效的解决方案是使用反射设置系统属性:
task wsimport {
  System.setProperty('javax.xml.accessExternalSchema', 'file')
  ...
}

使用extsystemProperty的其他所有解决方案对我都无效。 我已安装gradle 1.11。


我看到你的Gradle任务存在一个长期的问题,那就是如何支持多个版本的WSDL或者说如果你有多个XSD文件。文件不允许使用通配符。 - Himalay Majumdar
Arne,非常感谢您分享这个,它起作用了!!非常有帮助。 - vani saladhagu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接