Spring boot - JAxbException(jakarta.xml.bind.JAXBException: Implementation of jakarta xml binding-api not found on module path or classpath)

7.6k views Asked by At

java versionI have a maven project (version 1.8) and java version (1.8). I have a task where I have used eclipse moxy ( jaxb implementation) for creating xmls. I also have the jaxb.properties file in the package where the classes are present.

jakarta.xml.bind.JAXBContextFactory=org.eclipse.persistence.jaxb.JAXBContextFactory

The pom of the project looks like below:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
</build>
<dependencies>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>3.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>2.0.0-alpha4</version>
        </dependency>

        <dependency> 
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>3.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>3.0.0</version>
        </dependency>

    </dependencies>

This project is integrated into a microservice, as an artifact and the controller in the microservice does some unmarshalling and marshalling. The pom of the microservice looks like below:

<dependencies>
        <dependency>
            <groupId>XXX</groupId>
            <artifactId>ProjectX</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>3.0.0</version>
        </dependency>
<dependencies>

This works perfectly fine in the IDE. I can see the result i expect. however, when I go by the terminal and do a mvn packageand build the project, a jar is created in the target folder.

When I execute the jar, I get the following error:

jakarta.xml.bind.JAXBException: Implementation of Jakarta XML Binding-API has not been found on module path or classpath. -with linked exception: [java.lang.classNotFoundException: org.glassfish.jaxb.runtime.v2.ContextFactory]

Please let me know what I am doing wrong here? A beginner here

0

There are 0 answers