How to surpass gradle wsimport task JDK 8 access restrictions?

◇◆丶佛笑我妖孽 提交于 2019-12-08 16:09:55

问题


I have a wsimport task in my gradle build working fine until 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"
            )
        }
    }
}

When switching to JDK 8 (build 1.8.0-b129) I get the following error:

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.

Searching for the problem I found the following post (describing the problem also with Java 7 surprisingly): https://github.com/stianh/gradle-jaxb-plugin/issues/20 But I am unable to pass the environment/argument to wsimport/xjc.

How to disable this access or the restriction?


回答1:


The only working solution I found was to set a system property using reflection:

task wsimport {
  System.setProperty('javax.xml.accessExternalSchema', 'file')
  ...
}

All other solutions using ext or systemProperty did not work for me. I have gradle 1.11 installed.



来源:https://stackoverflow.com/questions/22044397/how-to-surpass-gradle-wsimport-task-jdk-8-access-restrictions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!