How to surpass gradle wsimport task JDK 8 access restrictions?
Asked Answered
E

1

10

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?

Epifaniaepifano answered 26/2, 2014 at 14:28 Comment(0)
E
7

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.

Epifaniaepifano answered 24/3, 2014 at 13:17 Comment(2)
One longterm concern I see with your gradle task, how will you support multiple versions of wsdl or let say if you have multiple xsds. file does not allow to use wildcardAlmedaalmeeta
Arne,Thanks so much for sharing this , it worked !! very help fullWhalen

© 2022 - 2024 — McMap. All rights reserved.