Using XJC version 2.3.0 fails
Closed this issue · 8 comments
I'm getting the following error when I use 2.3.0
for jaxb.xjcVersion
:
[ant:xjc] [ERROR] External parsing is disabled. Cannot parse URI: file:/home/boris/some-dir/some-file.dtd
[ant:xjc] unknown location
[ant:xjc]
The file does exists. This does not happen when using 2.2.11
. Any ideas?
Maybe this is a solution: https://stackoverflow.com/questions/23011547/webservice-client-generation-error-with-jdk8
Create a file named jaxp.properties under /path/to/jdk1.8.0/jre/lib and then write this line in it:
javax.xml.accessExternalSchema = all
Thanks for the answer but that doesn't fix the issue for me. I tried following some of the comments in this thread - I put that file in $JAVA_HOME/jre/lib
, in $JAVA_HOME/lib
, I put javax.xml.accessExternalDTD
in addition to javax.xml.accessExternalSchema
, I used System.setProperty('javax.xml.accessExternalSchema', 'all')
in a bunch of places in my build.gradle
- none of that helped. Any other ideas? I don't think the issue should be closed for now. :)
I am using Java 8 and the plugin works fine with XJC version 2.2.11
. It doesn't work with 2.3.0
, the same Java 8. So the problem is not in Java 8 I guess but somewhere else.
@boris-petrov I had the same problem. Setting system property enableExternalEntityProcessing
to true
helped me. Take a look at javaee/jaxb-dtd-parser@389ef2d. This is exactly the place where my code failed.
I'm creating xjc
task by my own so I can not give you direct solution for this plugin, but maybe code below will help you (worked for me):
configurations {
jaxWsTools
}
dependencies {
jaxWsTools 'com.sun.xml.ws:jaxws-tools:2.3.0'
}
task generateClassesFromDTD(description: 'Generates classes from DTD') {
doLast {
ant {
taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.jaxWsTools.asPath)
xjc(
package: 'some.package',
destdir: "${buildDir}/generated-sources",
schema: "${projectDir}/src/main/resources/schema.dtd",
fork: true,
{
arg line: '-XautoNameResolution -dtd'
jvmarg value: '-DenableExternalEntityProcessing=true'
}
)
}
}
}
I used ant.xjc.jvmarg
because System.setProperty
didn't work. After that java sources were generated but xjc
task failed with some other reason. Fork helped (see ant.xjc(fork: true)
).
@adrian-wozniak - thank you so much for your help! That seems to have fixed the issue, however then I hit another one: xjc failed
. I guess this is the "other reason" you mention. I read here that forking fixes that. However this plugin here doesn't support that.
@m-raab - is it possible to add support for forking?
@boris-petrov I'd the "xjc failed" issue, and fork helped. You don't really need this plugin to generate JAXB files, see code below.
configurations {
jaxb
}
dependencies {
implementation(...)
jaxb(
"com.sun.xml.bind:jaxb-core:$jaxbVersion",
"com.sun.xml.bind:jaxb-impl:$jaxbVersion",
"com.sun.xml.bind:jaxb-xjc:$jaxbVersion"
)
}
def schemaDir = "src/main/resources"
def generatedSources = "$buildDir/generated-sources"
def xjcOutputDir = "$generatedSources/java/main"
sourceSets {
main {
java {
srcDirs files(xjcOutputDir) {
builtBy("xjc")
}
}
}
}
task xjc {
inputs.dir "$schemaDir"
outputs.dir "$xjcOutputDir"
doLast {
project.ant {
taskdef(
name: "xjc",
classname: "com.sun.tools.xjc.XJCTask",
classpath: configurations.jaxb.asPath)
xjc(
destdir: "$xjcOutputDir",
package: "net.sourceforge.pmd",
schema: "$schemaDir/ruleset_2_0_0.xsd",
binding: "$schemaDir/binding.xjb",
encoding: "UTF-8",
fork: true
) {
arg(line: "-verbose")
arg(line: "-no-header")
arg(line: "-mark-generated")
}
}
}
}
@asarkar - thanks! I've been using something like this to workaround the issue, yes. Thanks again!