Showing posts with label JAXB. Show all posts
Showing posts with label JAXB. Show all posts

Saturday, June 2, 2018

Class has two properties of the same name exception

I think, it's because of the place where we use the "@XMLElement" annotation in the (bean) class. JAXB (annotation processor) considers the member field & getter method of the same field element as different properties, when we use the @XMLElement annotation at the field level it throws the IllegalAnnotationExceptions exception.

Below is the sample exception, which i encountered, when i placed the @XMLElement annotation on the property of my class

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 6 counts of IllegalAnnotationExceptions
Class has two properties of the same name "accountNum"
this problem is related to the following location:
at public java.lang.String com.test.finance.domain.ax.VendTable.getAccountNum()
at com.test.finance.domain.ax.VendTable
this problem is related to the following location:
at private java.lang.String com.test.finance.domain.ax.VendTable.accountNum
at com.test.finance.domain.ax.VendTable



To resolve this issue, JAXB offers a lot of flexibility when interacting with your object model. One area is configuring the use of fields or properties to access the data in your domain objects. This is specified as an XmlAccessType (PUBLIC_MEMBER, PROPERTY, FIELD, or NONE) via the @XmlAccessorType annotation. So, you add the XmlAccessType to your class, as shown below, will resolve the issue.

@XmlAccessorType(XmlAccessType.FIELD)


Happy Programming...!!!

Tuesday, March 15, 2016

Error: Could not find or load main class com.sun.tools.internal.xjc.XJCFacade - Eclipse

When your eclipse project libraries are not pointing to JDK, and instead it is pointing to the JRE, you will get this error "Error: Could not find or load main class com.sun.tools.internal.xjc.XJCFacade". If the JDK path was not configured in your installed JRE's please do the following.

From Eclipse Click File > Properties, select Java Build Path and select Libraries Tab.
In the Libraries Tab, select the JRE system library and click Edit, which will pop up a window.

Then click Installed JREs, button, which will pop up a window, which will display the JRE installed, as below.



Now Click Add, and provide the path, where your java jdk have been installed. In the below image, i have configured the path, where my Java JDK has been installed. Once set the path, it will fetch all the JRE libraries under that folder, as shown below.



Once you clicked finish button, the JDK entry will be shown in the Installed JREs window. Now select the newly added path and click apply. Now in the JRE System library window, Click on the Alternate JRE dropdown, it will list the jdk which was added by us, select that and click finish. This will change your JRE System library point to the JDK, what we have installed. Now select the xsd file and generate the JAXB classes, it will generate the classes successfully without any error.

Happy Programming.