Wednesday, June 17, 2015

How to get ride of Two declarations cause a collision in the ObjectFactory class, ] A class/interface with the same name or This error is caused because on Windows you cannot have both

Generally we use wsimport to auto generated JAVA class for consuming WSDL base web service.

Many times it happens we use to see this specific type of error messages while auto generating code.

 [ERROR] Two declarations cause a collision in the ObjectFactory class.
[ERROR] A class/interface with the same name "XXXClassName" is already in use. Use a class customization to resolve this conflict.
[ERROR] This error is caused because on Windows you cannot have both "XXXClassName.java" and "xxxClassname.java" in the same directory.
[ERROR] This error is caused because on Windows you cannot have both "xxxClassName.java" and "PersistentObjectOfInt.java" in the same directory.

This are the possible ways which I tried and able to get ride of these errr:

Option 1:- This is simple option which works 90% of times. Use –B-XautoNameResolution.
Option 2:- This error is created because your XSD or WSDL is forcing to wsimport command to create java class of same name in same package. So if we not so strict in creating the auto generated source file in our specific folder neglect –p option.
Option 3:- Create binding.xml to get ride of this error. Through this we can tell wsimport to create class with the name specified by us rather than auto generating class name. But as stated in this if we had more than one schema in WSDL then for all name conflict we have to do the same.
Make sure when we create binding.xml  add it command prompt using –b option.

Example of binding.xml
        jxb:bindings node="//xs:element[@name='cxml.payment']/xs:complexType">
     name="CxmlInnerPaymentType" />




No comments: