Invalid JAXP API when unmounting JAXB

I have a JAXB object that I can disable. However, if I add the Element [] field annotated with @XmlAnyElement, when I try to untie it, it throws:

java.lang.IllegalStateException: you are using an invalid JAXP api or implementation. JAXP api / implementation version 1.3.1 (included with JDK6) or higher. If you are using ant, make sure you are using ant 1.7.0 or later β€” older versions of ant contain JAXP api / impl version 1.2 (in xml-apis.jar). If you want to use older versions of ant, you need to configure it to use the JAXP api / impl versions.

This is done from the TestNG test, which I run through the Eclipse plugin. I am running with a 1.6 JDK and configured maven to exclude older versions of the xml-apis jar, but I cannot get it to work. I suppose I'm still compiling incompatible versions of libraries from somewhere, but I don’t know where.

Running through Eclipse directly I get:

29-Aug-2013 10:04:08 com.sun.xml.bind.v2.util.XmlFactory createTransformerFactory SEVERE: null java.lang.AbstractMethodError: javax.xml.transform.TransformerFactory.setFeature(Ljava/lang/String;Z)V at com.sun.xml.bind.v2.util.XmlFactory.createTransformerFactory(XmlFactory.java:155) at com.sun.xml.bind.v2.runtime.JAXBContextImpl.createTransformerHandler(JAXBContextImpl.java:747) at com.sun.xml.bind.v2.runtime.unmarshaller.DomLoader$State.<init>(DomLoader.java:75) at com.sun.xml.bind.v2.runtime.unmarshaller.DomLoader.startElement(DomLoader.java:118) at com.sun.xml.bind.v2.runtime.unmarshaller.ProxyLoader.startElement(ProxyLoader.java:60) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:501) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:480) at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:150) at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source) at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:218) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:190) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184) at com.gtspt.vrs.parser.AbstractParserTest.unmarshal(AbstractParserTest.java:33) at com.gtspt.vrs.parser.AbstractParserTest.testParser(AbstractParserTest.java:26) at com.gtspt.vrs.parser.TestResultsParser.testParser(TestResultsParser.java:17) at com.gtspt.vrs.parser.Test.main(Test.java:16) 
+6
source share
6 answers

The problem seems to be related to the old version of Xalan. It seems that a minimum of version 2.7.0 is required with JDK 5. Another library pulled the older version, so I excluded it from the Maven assembly, and now everything looks good.

+12
source

In my case, it was caused by the old version of xercesImpl . Dependence below fixed

  <dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> <version>2.11.0</version> </dependency> 
+4
source

Alternatively, if you have a maven or JPA project, you can right-click on the dependency directory, add the dependency, and search for xalan. Add any version 2.7.0 and up to the xalan: xalan list.

+1
source

I encountered the same error with the same formulations, but this turned out to be a completely different problem than the dependency problem, for example, the proposed error. Therefore, I share my meeting here, in case someone there can also win.

There was something similar in my code:

 public class ImageObject { @XmlElementWrapper(name="shapes") @XmlAnyElement(lax=true) @XmlElementRefs({ @XmlElementRef(name = "circle", type=Circle.class), @XmlElementRef(name = "square", type=Square.class), @XmlElementRef(name = "rectangle", type=Rectangle.class), @XmlElementRef(name = "triangle", type=Triangle.class) }) private List<Object> shapes; ... } 

And in the Rectangle class, I had a typo in the element name specified for @XmlRootElement - "retangle" , not matching the name of the "rectangle" inside @XmlElementRef in the ImageObject class:

 @XmlRootElement(name = "retangle") public class Rectangle extends Shape { @XmlAttribute private String colour; @XmlAttribute private String width; ... } 

So, pay attention to this if you use the @XmlElementRef annotation.

0
source

I solved this problem by removing xalan from my project. I am using JDK7 in my project

0
source

I solved this problem with the following code. I am using JDK8 in my project

 System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); 
0
source

Source: https://habr.com/ru/post/952667/


All Articles