0

I am trying to parse an XML file to Java using JAXB. However, when I do so, I get an error related to what I believe to be the annotation. I have looked at other stack overflow answers but nothing seems to be able to help me solve the issue I am having. Error:

javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:241)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:477)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:656)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:599)
    at Driver.meTo(Driver.java:27)
    at Driver.main(Driver.java:15)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
    at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:594)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:239)
    ... 5 more

I have about 4 classes in total that the JAXB would utlize but specifically I just want to get the information in the module portion of the XML. I used a XML to Java POJO to do the conversion. Though it does not come wiht the @XML stuff

XML:

<?xml version="1.0" encoding="UTF-8"?>
<results
        xmlns="info"
        xmlns:coll="info"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="info">

    <IIsWebServiceImpl array="1"
        guid="063D0DD72D5F3A46B118D7A963306361" xsi:type="coll:com.platform.model.topology.app.web.klm.KLMWebService">
        <modules array="1" guid="FBVRKJNR75858NND2UJ3J2IC9C9R" xsi:type="coll:com.collation.platform.model.topology.app.web.klm.KLMModule">
            <fileName>D:\pubKSRF</fileName>
            <isPlaceholder>false</isPlaceholder>
            <displayName/>
            <hierarchyDomain>app.web.klm</hierarchyDomain>
            <hierarchyType>KLMModule</hierarchyType>
        </modules>
        <modules array="2" guid="IJECI89585U5FJIDNVU3FI2NF" xsi:type="coll:com.platform.model.topology.app.web.klm.KLMModule">
            <fileName>d:\SRFdata</fileName>
            <isPlaceholder>false</isPlaceholder>
            <displayName/>
            <hierarchyDomain>app.web.klm</hierarchyDomain>
            <hierarchyType>KLMModule</hierarchyType>
        </modules>
        <modules array="3" guid="VNJFVFV8238DNCNCJ3J4JNDIEJC875" xsi:type="coll:com.platform.model.topology.app.web.klm.KLMModule">
            <fileName>D:\srfData</fileName>
            <isPlaceholder>false</isPlaceholder>
            <displayName/>
            <hierarchyDomain>app.web.klm</hierarchyDomain>
            <hierarchyType>KLMModule</hierarchyType>
        </modules>
        <isPlaceholder>false</isPlaceholder>
        <displayName/>
        <hierarchyDomain>app.web.klm</hierarchyDomain>
        <hierarchyType>KLMWebService</hierarchyType>
    </IIsWebServiceImpl>
</results>

Pom.xml:

 <dependencies>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.11</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0-b170201.1204</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.activation/activation -->
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.0-b170127.1453</version>
        </dependency>
    </dependencies>
kane_004
  • 253
  • 3
  • 18
  • Why do you believe this is due to an annotation? It looks like your runtime classpath contains the JAXB API, but not an implementation. – VGR Dec 23 '19 at 20:51
  • @VGR I don't think so let me post my ```pom.xml``` I believe it is probably the dependency – kane_004 Dec 23 '19 at 21:08
  • I recall having JAXB binding issues a few years ago. What are the constructors like in your class? No Arg constructors are a pre-requisite IIRC (or easiest way to go). More on it here. https://stackoverflow.com/q/9268074/495157 – JGFMK Dec 23 '19 at 21:29

0 Answers0