stianh / gradle-jaxb-plugin

Gradle plugin for generating jaxb classes.
17 stars 11 forks source link

Failure due to external resource restriction in recent Java 7/8 #20

Closed estan closed 10 years ago

estan commented 11 years ago

Hi,

I recently upgraded my OpenJDK (7.u40_2.4.0 -> 7.u40_2.4.1) and I think I've been bitten by the same problem as described in [1]:

:generateSchemaSource FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateSchemaSource'.
> java.lang.AssertionError: org.xml.sax.SAXParseException; systemId: jar:file:/home/estan/.gradle/caches/artifacts-23/filestore/com.sun.xml.bind/jaxb-xjc/2.2.7/jar/f351eed8b1ee9a1dd242bf81bf7a391c40a16d18/jaxb-xjc-2.2.7.jar!/com/sun/tools/xjc/reader/xmlschema/bindinfo/binding.xsd; lineNumber: 52; columnNumber: 88; schema_reference: Failed to read schema document 'xjc.xsd', because 'file' access is not allowed due to restriction set by the accessExternalSchema property.

I'm not sure if the Gradle plugin is able to solve this, since I can't find a way in the Ant task to control the JAXP features used (to turn off the now default restricted access to external resources), but I'll file it as a bug here since at the moment I've had to downgrade my JDK to work around the problem.

Thanks a lot for an otherwise nice plugin!

[1] https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN-80

estan commented 11 years ago

If somehow ANT_OPTS could be passed to the Ant task, it could probably be worked around by passing -Djavax.xml.accessExternalSchema=file, but so far I haven't found a way to do this :(

I tried both hacking the plugin to do ant.properties['env.ANT_OPTS'] = '-Djavax.xml.accessExternalSchema=file' and systemProp.javax.xml.accessExternalSchema=file in my gradle.properties.

Endron commented 10 years ago

I am not using this plugin but ran into the same problem when using the xjc ant task with gradle. Your comment makes me believe that this plugin somehow also uses the ant task.

I fixed the problem by passing the "-disableXmlSecurity" argument.

ant.taskdef(name:'xjc', classname:'com.sun.tools.xjc.XJC2Task', classpath:configurations.generateSources.asPath)
ant.xjc(schema:'some.xsd", destdir:generatedSources, encoding:encoding, catalog:catalogFile) {
                arg(value:"-disableXmlSecurity")
            }

I hope this helps with fixing the issue.

highsource commented 10 years ago

Author of the maven-jaxb2-plugin. https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN-80 is now resolved in 0.9.0. So relevant JAXP properties accessExternalSchema and accessExternalDTD can be controlled now. Further properties are out of the scope. accessExternalSchema and accessExternalDTD can be controlled and set to "all" by default.

stigkj commented 10 years ago

Sorry for taking this long to answer, but we are not maintaining this plugin anymore. You should look at jacobono's alternative instead.

estan commented 10 years ago

Ah. Thanks. Right now I'm actually working on the very same product I was working on when I had this problem, almost exactly a year ago :) I'll look into jacobono's plugin. Though right now I'm not having any trouble with this one.

vhariprakash commented 8 years ago

solved : ref : http://stackoverflow.com/questions/23011547/webservice-client-generation-error-with-jdk8 Create a file named jaxp.properties (if it doesn't exist) under /path/to/jdk1.8.0/jre/lib and then write this line in it:

javax.xml.accessExternalSchema = all

That's all. Enjoy JDK 8.