title: Retrieve simple XML rest web service data using jersey
body: <p>I tried a simple example to make rest web service using jersey in eclipse IDE. This web service assumed to return a simple information in XML format for an object as shown in the class: </p>
  
  <pre><code>import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  
  @Path("aliens")
  public class AlienResource {
  
      @GET
      @Produces(MediaType.APPLICATION_XML)
  
      public Alien getAlien() {
          System.out.println("getAlien called successfully!!!!");
  
          Alien a1 = new Alien();
          a1.setName("Ahmed");
          a1.setPoints(90);
          return a1;
      }
  
  }
  </code></pre>
  
  <p>I am using Tomcat web server 9. I tried to use different versions of jersey without any errors seen in the console but I still got an internal server error 500. </p>
  
  <p><em>this is my pom.xml file</em> </p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.ali&lt;/groupId&gt;
      &lt;artifactId&gt;try2&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;try2&lt;/name&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;try2&lt;/finalName&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.5.1&lt;/version&gt;
                  &lt;inherited&gt;true&lt;/inherited&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-bom&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-servlet-core&lt;/artifactId&gt;
              &lt;!-- use the following artifactId if you don't need servlet 2.x compatibility --&gt;
              &lt;!-- artifactId&gt;jersey-container-servlet&lt;/artifactId --&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
              &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
              &lt;version&gt;2.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- uncomment this to get JSON support
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-media-json-binding&lt;/artifactId&gt;
          &lt;/dependency&gt;
          --&gt;
      &lt;/dependencies&gt;
      &lt;properties&gt;
          &lt;jersey.version&gt;2.26-b03&lt;/jersey.version&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>how to solve this problem?</strong></p>
  
  <blockquote>
    <p>note: <strong>It works perfectly with JSON format.</strong></p>
  </blockquote>
  
  <p><em>A model class:</em> </p>
  
  <pre><code>import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement
  public class Alien {
      private String name;
      private int points;
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public int getPoints() {
          return points;
      }
      public void setPoints(int points) {
          this.points = points;
      }
  }
  </code></pre>