tags:

views:

139

answers:

1

When binding on some valid XML documents using Ant's xjc2 task, I get the following failure message:

[xjc2] [ERROR] null
[xjc2] unknown location

The documents are very similar to other files which have bound successfully, all imported schemas exist. Running xjc in verbose mode produced:

Parent is not Defined Class...I cannot get the fields from this class

Anyone have any idea what this means?

+2  A: 

Schema Correctness Check

In our use of XJC we have seen a similar problem (see the link below) that was solved by disabling the schema correctness check:

Try the following System property to disable the schema correctness check.

-Dcom.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.noCorrectnessCheck=true

For Ant, try:

<xjc target="src">
  <schema dir="src" includes="**/*.xsd" excludes="**/debug.xsd"/>
  <arg value="-nv" />
</xjc>

From the following page the -nv parameter relates to the schema correctness check:

Getting into the Code

You could try interacting with XJC programmatically (see below) and plug-in your own EntityResolver to see where the import/include fails:

import com.sun.codemodel.*;
import com.sun.tools.xjc.*;
import com.sun.tools.xjc.api.*;

SchemaCompiler sc = XJC.createSchemaCompiler();
sc.setEntityResolver(new YourEntityResolver());
sc.setErrorListener(new YourErrorListener());
sc.parseSchema(SYSTEM_ID, element);
S2JJAXBModel model = sc.bind();
Blaise Doughan
I tried providing this argument to the xjc2 task as <arg value="-Dcom.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.noCorrectnessCheck=true" />. I added it as a child to the <xjc2> node (next to my other arguments). I received the following error:"unrecognized parameter -Dcom.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.noCorrectnessCheck=true"
Tom Tresansky
Also tried without the "=true" bit. Same result.
Tom Tresansky
I've updated my answer. The -nv parameter in the ant task appears to relate to the schema correctness check.
Blaise Doughan
The -nv parameter works, however, the error remains. I have also used an external tool to validate the schema without problems, so I don't think that is the problem here. Also, I'm running the <xjc2> task, NOT <xjc> (though the param still works).
Tom Tresansky
Any chance there is a proxy issue? I have tried to reproduce your issue by disabling the HTTP proxy in my env, and I get an error, but it is different than yours, but it's probably worth a try. I have added some details on how to programmatically access the XJC. If you pass in your own EntityResolver you may get a better handle on which schema is causing the failure.
Blaise Doughan
The following thread may be of use. IT talks about the hash '#' character in the URI causing an "unkown location" error. http://old.nabble.com/xjc-2.2-and-the-hash-character-td26957314.html
Blaise Doughan
Solved it! Combination of issues, able to track them down using the link and your suggestions on running programmatically! Thank you so much for all your help, you definitely earned that bounty!
Tom Tresansky