Thursday, 27 July 2017

Resolve ObjectFactory Collisions in JAVA

How to resolve ObjectFactory Collisions in JAVA

In my previous article I have explained how to generate the web service classes.If you have not already read the topic then I would advise you to do so. Moving on, we can sometimes get an error like below

[ERROR] Two declarations cause a collision in the ObjectFactory cl
  line 1191 of file:/D:/RAMEEZ/Web%20Services/TeamBpl/TeamBpl3.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 981 of file:/D:/RAMEEZ/Web%20Services/TeamBpl/TeamBpl3.xsd

This is a very common issue we face, and the way to resolve this is to simply write a XML file having a JAXB binding configuration.

Simple Steps for Clear Understanding:

Here are a few simple steps with images to help you fix the issue quickly :)


Analyze the issue.
From the above error log we see line number 1191 and 981 have issues in the
XSD Schema file. Lets look into the XSD file. See below.


So this is happening because the "name" attribute is somehow causing collision when the WSDL file is getting parsed.


To solve this simple open a new file in Notepad(or any text editor you use) and name it something like "conflict.xml".


Copy it from here.

<jxb:bindings version="1.0" xmlns:jxb="" xmlns:xs="">

 <jxb:bindings node="/xs:schema" schemalocation="TeamBpl3.xsd">
  <jxb:bindings schemalocation="TeamBpl3.xsd">
   <jxb:bindings node="./xs:element[@name='MediaUrl']">
    <jxb:factorymethod name="RootMediaElement">



Now run the "wsimport" command with the -b switch. This is called the binding (-b).

wsimport [WSDL_FILE.wsdl] -b conflict.xml -keep -verbose


This will generate the stub classes properly without any issues.


When you have multiple collisions then in that case you have to write multiple jxb:bindings for each. Means you have to repeat line number 5 to 11 from STEP 3.

Hope this helps!

No comments:

Post a Comment

Coder Magnet
CoderMagnet is full of resources from our daily development activities. It has solutions for common problematic scenarios in technologies like Java 8, AEM, JCR and also occasionally gives you tips on Blogger as well.