Do I need to include the Jersey Jars in my EAR on Glassfish4.0 server?

帅比萌擦擦* 提交于 2019-12-12 01:25:56

问题


I am trying to use Firefox poster to test a Jersey restful webservice running on Glassfish 4.0. I am getting a HTTP Server 500 error returned to the Poster output when I return a java class as xml. I do not get an error when I return a String as xml. This makes me wonder if I need to include any of the JAX-RS jars or Jersey jars in my ear on Glassfish. I was thinking these were included in the Glassfish modules so I am not including them in my WEB-INF lib.

Here is an example of what works, returns xml to firefox poster:

 @GET
@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/x-javascript", MediaType.APPLICATION_OCTET_STREAM } )
@Path( "/getTest/" )
public String getXml()
{
    return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";

}

Here is an example of what throws the Internal server error 500:

 @GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path( "/getTodo/" )
public Todo getXML() {
  Todo todo = new Todo();
  todo.setSummary("This is my first todo");
  todo.setDescription("This is my first todo");
  return todo;
}

 @XmlRootElement
 // JAX-RS supports an automatic mapping from JAXB annotated class to XML and JSON    
 // Isn't that cool?
 public class Todo {
   private String summary;
   private String description;
   public String getSummary() {
     return summary;
   }
   public void setSummary(String summary) {
     this.summary = summary;
   }
   public String getDescription() {
     return description;
    }
   public void setDescription(String description) {
     this.description = description;
   }
}

FYI - I am loosely following the blog here - restBlog


回答1:


You definitely don't need to include any of the standard jersey files in your war or ear file for them to be accessible at runtime. I've certainly had exactly the kind of thing you're doing working fine, either using maven or native netbeans 7.3.1 projects.

I suggest you look at the glassfish server.log file to see precisely what the detailed error you are getting is. If you are missing needed jars, that should tell you.



来源:https://stackoverflow.com/questions/17600050/do-i-need-to-include-the-jersey-jars-in-my-ear-on-glassfish4-0-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!