Skip to main content

"root element collision" while trying to use commonality of two schemas

6 replies [Last post]
albretch
Offline
Joined: 2005-08-15

Hi *,

I basically have two xml schemas which only differ in one attribute, so I built both around their commonality.

// __ NQItm00.xsd
<?xml version="1.0" encoding="UTF-8"?>

// __
<?xml version="1.0" encoding="UTF-8"?>

// __ with commons00.xsd as:
<?xml version="1.0" encoding="UTF-8"?>

// __
Everything parses fine independently but when yo try to load both schemas you get:

// - - - - - - - - - - - - - - - - - - - - - -
javax.xml.bind.JAXBException: root element collision detected for {}Aprx - unable to create JAXBContext with the given contextPath
at jaxb.NQItm00.impl.runtime.GrammarInfoFacade.detectRootElementCollisions(GrammarInfoFacade.java:114)
at jaxb.NQItm00.impl.runtime.GrammarInfoFacade.(GrammarInfoFacade.java:35)
at jaxb.NQItm00.impl.runtime.GrammarInfoFacade.createGrammarInfoFacade(GrammarInfoFacade.java:185)
at jaxb.NQItm00.impl.runtime.DefaultJAXBContextImpl.(DefaultJAXBContextImpl.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at com.sun.xml.bind.ContextFactory_1_0_1.createContext(ContextFactory_1_0_1.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:96)
at javax.xml.bind.ContextFinder.searchcontextPath(ContextFinder.java:229)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:149)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:281)
at JAXB06.setCtxt(JAXB06.java:106)
at TestJAXB06.main(TestJAXB06.java:9)
--------------- linked to ------------------
javax.xml.bind.JAXBException
- with linked exception:
[javax.xml.bind.JAXBException: root element collision detected for {}Aprx - unable to create JAXBContext with the given contextPath]
at com.sun.xml.bind.ContextFactory_1_0_1.createContext(ContextFactory_1_0_1.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:96)
at javax.xml.bind.ContextFinder.searchcontextPath(ContextFinder.java:229)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:149)
// - - - - - - - - - - - - - - - - - - - - - - - - - -

Why is this happening? How could you fix it?

Thanks
Albretch

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09

This looks like a 1.0 issue, so please send this to the users list or file an issue in https://jaxb.dev.java.net/

I'm not so keen on decyphering unindented schema sources, to be honest.

Generally speaking "root element collision" means you have two global elements of the same name in the schema set.

albretch
Offline
Joined: 2005-08-15

> This looks like a 1.0 ...
lbrtchx: I think I am using JAXB 2.0 but I will double check

> I'm not so keen on decyphering unindented schema
sources, to be honest.
lbrtchx: Well, I didn't have the schemas this way. It is just the way it was presented

> Generally speaking "root element collision" means you have two global elements of the same name in the schema set.
lbrtchx: I speak English :-)
My problem is trying to fix this "collosion" how excatly do you rid it. I mean what do you write where in order to free it?

Could you at least point me to some tutorials on this, not justs 'spex'? I searched on the wen on these "root element collision" and found basically nothing that helped me out of it

Thanks

Message was edited by: albretch

kohsuke
Offline
Joined: 2003-06-09

You must have two classes that are mapping to the same XML root element. Those two classes might look identical (other than their fully-qualifed class name), or they might be coming from two different schema definitions.

You can't have two such classes in one JAXBContext. So fixing this error means identifying the offending class pair and getting rid of one of them.

But it could be a problem in the way you compiled schemas, or a problem in the way your schema is written. You could be hitting a common separate-compilation related issue, there might be a bug in the RI, or it might be some operator error. There's a lot of possibility, and the first step in diagnosing the problem is to look at the schema.

I also suspect you are using 1.0, which makes the issue even more compliated.

That's why I asked you to file an issue with the schema as an attachment.

albretch
Offline
Joined: 2005-08-15

Well, I tried to redo the whole thing step by step making sure I had the latest version of JAXB.

However I got totally new errors:

xjc.sh: line 52: syntax error: unexpected end of file

stemming from I am not sure what.

My xjc.sh I pasted at the end.

Here is exactly what I did for you to know my base:

// - - - - - - - - - - - - reinstalling JAXB
// __ first I downloaded the latest version of JAXB2's JAXB_RI_20050622.jar from this site
[root@localhost JAXB]# pwd
/usr/local/JAXB
[root@localhost JAXB]# ls -l
total 8768
-r--r--r-- 1 root root 8956717 Jan 1 2002 JAXB_RI_20050622.jar
[root@localhost JAXB]# md5sum *.*
4169da4e8f2c13b045e869a2f1dae5c0 JAXB_RI_20050622.jar

// __ the I installed JAXB
[root@localhost JAXB]# java -jar JAXB_RI_20050622.jar

// __ then I updated /etc/profile
...
JAXB_HOME=/usr/local/JAXB/jaxb-ri-20050622
...
JAXB_LIB=$JAXB_HOME/jaxb/lib
CLASSPATH=$CLASSPATH:$JAXB_LIB/jaxb-api.jar
CLASSPATH=$CLASSPATH:$JAXB_LIB/jaxb-impl.jar
CLASSPATH=$CLASSPATH:$JAXB_LIB/jaxb-xjc.jar

// __ I did notice jaxb-libs.jar was nowhere to be found in the new $JAXB_HOME/lib folder so, I commented it from the CLASSPATH
#CLASSPATH=$CLASSPATH:$JAXB_LIB/jaxb-libs.jar

// __ so that the CLASSPATH now looks like (libraries related to XML processing):
[root@localhost ~]# echo $CLASSPATH
...
:/usr/local/jwsdp-1_6/jaxp/lib/jaxp-api.jar
:/usr/local/jwsdp-1_6/jaxp/lib/endorsed/dom.jar
:/usr/local/jwsdp-1_6/jaxp/lib/endorsed/sax.jar
:/usr/local/jwsdp-1_6/jaxp/lib/endorsed/xalan.jar
:/usr/local/jwsdp-1_6/jaxp/lib/endorsed/xercesImpl.jar
:/usr/local/jwsdp-1_6/jwsdp-shared/lib/jax-qname.jar
:/usr/local/jwsdp-1_6/jwsdp-shared/lib/namespace.jar
:/usr/local/jwsdp-1_6/jwsdp-shared/lib/relaxngDatatype.jar
:/usr/local/jwsdp-1_6/jwsdp-shared/lib/xsdlib.jar

:/usr/local/JAXB/jaxb-ri-20050622/lib/jaxb-api.jar
:/usr/local/JAXB/jaxb-ri-20050622/lib/jaxb-impl.jar
:/usr/local/JAXB/jaxb-ri-20050622/lib/jaxb-xjc.jar
...
[root@localhost ~]#

// __ making sure JAXB_HOME is set and export'ed
[root@localhost XSD06]# echo $JAXB_HOME
/usr/local/JAXB/jaxb-ri-20050622
[root@localhost XSD06]# cd $JAXB_HOME/lib
[root@localhost lib]# pwd
/usr/local/JAXB/jaxb-ri-20050622/lib

// __ that the PATH is set
[root@localhost XSD06]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin
:/usr/local/sbin
:/usr/local/bin
:/sbin
:/bin
:/usr/sbin
:/usr/bin
:/usr/X11R6/bin
:/opt/jdk/jdk1.5.0_03/bin
:/usr/local/JAXB/jaxb-ri-20050622/bin
:/usr/local/ant/apache-ant-1.6.5/bin
:/root/bin

// __ and that I have the right? thing
[root@localhost lib]# ls -l
total 5088
-rw-r--r-- 1 root root 54829 Aug 31 04:35 activation.jar
-rw-r--r-- 1 root root 980557 Aug 31 04:35 jaxb1-impl.jar
-rw-r--r-- 1 root root 338838 Aug 31 04:35 jaxb-api-doc.zip
-rw-r--r-- 1 root root 66168 Aug 31 04:35 jaxb-api.jar
-rw-r--r-- 1 root root 128254 Aug 31 04:35 jaxb-api-src.zip
-rw-r--r-- 1 root root 687807 Aug 31 04:35 jaxb-impl.jar
-rw-r--r-- 1 root root 2818723 Aug 31 04:35 jaxb-xjc.jar
-rw-r--r-- 1 root root 49672 Aug 31 04:35 jsr173_1.0_api.jar
[root@localhost lib]# md5sum

[root@localhost lib]# md5sum *.*
c0fd63acec238f02ab6ee8df40517bc5 activation.jar
08cb8e133a6b3018c4bdffc62fb0266d jaxb1-impl.jar
cb1107333939e724f251efc5df486f7f jaxb-api-doc.zip
a8e765cb40f6fc304e972507e4414f55 jaxb-api.jar
74a32e44819fec085ad1b9ac6694eb65 jaxb-api-src.zip
186734cdfbd549f5ab789e9a7a8037dd jaxb-impl.jar
6954f655bdfb3afa53b74c9fc52c98bc jaxb-xjc.jar
1ee49530106d55428c11653948ffd159 jsr173_1.0_api.jar

// __ then when I tried recreating and recompiling the jAXB classes
[root@localhost lib]# cd /home/tcbox00/dev/java/survey/XSD06
[root@localhost XSD06]# sh xjc.sh -p ./jaxb.NQItm00 ./NQItm00.xsd
: command not foundb-ri-20050622/bin/xjc.sh: line 6:
/usr/local/JAXB/jaxb-ri-20050622/bin/xjc.sh: xjc.sh: line 52: syntax error: unexpected end of file

// - - - - - - - - - - xjc.sh

#!/bin/sh
#
# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
# SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
#

#
# Make sure that JAXB_HOME and JAVA_HOME are set
#
if [ -z "$JAXB_HOME" ]
then
# search the installation directory

PRG=$0
progname=`basename $0`
saveddir=`pwd`

cd `dirname $PRG`

while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname $PRG`/$link"
fi
done

JAXB_HOME=`dirname "$PRG"`/..

# make it fully qualified
cd "$saveddir"
JAXB_HOME=`cd "$JAXB_HOME" && pwd`

cd $saveddir
fi

[ `expr \`uname\` : 'CYGWIN'` -eq 6 ] &&
{
JAXB_HOME=`cygpath -w "$JAXB_HOME"`
}

if [ -n "$JAVA_HOME" ]
then
JAVA="$JAVA_HOME/bin/java"
else
JAVA=java
fi

exec "$JAVA" $XJC_OPTS -jar "$JAXB_HOME/lib/jaxb-xjc.jar" "$@"

// - - - - - - - - - - - - - - - - - - - - -

I am baffled at finding all this JAXB thing so complicated now, because the thing I loved about it was exactly how much time it was letting me save. :-(

Will I be done with this JAXB comlications at some point? I mean trying to fix one thing makes me find yet other errors :-)

Thanks
Albretch

bhaktimehta
Offline
Joined: 2004-03-18

Hi Albretch,
I could not reproduce this problem and could compile your schema using jaxb-ri-20050622.

/cygdrive/d/webjaxb/jaxb-ri-20050622/bin %echo $CLASSPATH

/cygdrive/d/webjaxb/jaxb-ri-20050622/bin %sh xjc.sh -p junk NQItm00.xsd
parsing a schema...
compiling a schema...
junk\A.java
junk\Ap.java
junk\Aprx.java
junk\NQTp.java
junk\NQx.java
junk\ObjectFactory.java
junk\QAns.java
junk\QTp.java
junk\THead.java
junk\THeaders.java

Please can you try again. Btw you do not need to set any CLASSPATH. jaxb-xjc.jar has the classpath entries.

Regards,
Bhakti

kohsuke
Offline
Joined: 2003-06-09

One general observation. JAXB_HOME and JAXB_LIB are not necessary.

We'll check the version you tried (Bhatki, we should probably try it
on a real Unix system, not cygwin), but if scripts break, you can always
do:
[code]
java -jar /path/to/jaxb-xjc.jar ...
[/code]
instead of using a batch file / shell script.