I have a Jersey Code containing AlienResource file for handeling request and Alien.java code and some dependencies. i am trying to render xml content on web page but it is giving error as application/xml not found.
AlienResource.java
package com.Ritesh.Jerseyyy;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
@Path("alien")
public class AlienResource {
@GET
@Produces(MediaType.APPLICATION_XML)
public Alien getAlien() {
Alien a = new Alien();
a.setAid(101);
a.setAname("Ritesh");
return a;
}
}
Alien.java
package com.Ritesh.Jerseyyy;
import jakarta.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Alien {
private int aid;
private String aname;
public int getAid() {
return aid;
}
public void setAid(int aid) {
this.aid = aid;
}
public String getAname() {
return aname;
}
public void setAname(String aname) {
this.aname = aname;
}
@Override
public String toString() {
return "Alien [aid=" + aid + ", aname=" + aname + "]";
}
}
and this pom.xml file with below dependies
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<!-- uncomment this to get JSON support-->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>4.0.1</version>
</dependency>
i am getting error as SEVERE: MessageBodyWriter not found for media type=application/xml
can some one please help ?
I am getting error and want it to resolve
New contributor
Ritesh Parwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.