Hashim Abbas
Hashim Abbas

Reputation: 111

Jersey 2.25.1 HTTP STATUS 500 Error when using MediaType.APPLICATION_XML

Since 2 days I am stuck with this issue and it is not going away.

A simple explanation what I want to do:

1) build a simple Restful web service using jersey 2.25.1 which displays XML as the output.

2) Deploy it on Tomcat

Just for Info My JSON and plain text restful webservice is working fine. I am only getting errors for XML when using @RootElement. I am using java 1.8, Jersy 2.25.1, tomcat 8.5

I am getting the below error again and again and don't understand how to resolve it:

Error Image

I have tried these two examples as well but no luck:

1) https://www.mkyong.com/webservices/jax-rs/download-xml-with-jersey-jaxb/

I have tried multiple examples but still, This error shows up and I cannot resolve it. Can some one please explain me why this is coming up.

Thanks in Advance.

Upvotes: 2

Views: 824

Answers (2)

Dupinder Singh
Dupinder Singh

Reputation: 7769

Just a little update, even updating I am also creating basic Jeresy webApp and faced same issue, but this above solution is not enough.

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

After building and on hit our endpoint, one new issue will come

javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: com/sun/xml/bind/v2/model/annotation/AnnotationReader

To resolve this you need to add following dependencies too into pom.xml

<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0.1</version>
</dependency>

        <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl -->
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.1</version>
</dependency>

So this is the complete solution, to make your Jeresy webApp work

Upvotes: 0

Hashim Abbas
Hashim Abbas

Reputation: 111

Thank you everyone I fixed the issue... maybe this info will help everyone who is searching for the problem. The major problem was that I don't know for what reason If I make a new maven project on eclipse with Group Id org.glassfish.jersey.archetypes Artifact Id jersey-quickstart-webapp version 2.25.1, eclipse used to create a whole project with POM file as it suppose to and in this project if I even ran https://jersey.java.net/documentation/2.5.1/media.html#d0e7129 this simple jersey official demo, I was getting the same annotation error. I think in the POM file which eclipse create has a lot of things which I didn't needed and which must be overlapping with other things.

So in the above mkyong example I just added below dependency and it is now working just fine:

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

Thanks everyone for helping me out. :)

Upvotes: 1

Related Questions