我是否需要在 Glassfish4.0 服务器上的 EAR 中包含 Jersey 罐? [英] Do I need to include the Jersey Jars in my EAR on Glassfish4.0 server?

查看:28
本文介绍了我是否需要在 Glassfish4.0 服务器上的 EAR 中包含 Jersey 罐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Firefox 海报来测试在 Glassfish 4.0 上运行的 Jersey 宁静网络服务.当我将 java 类作为 xml 返回时,我收到一个 HTTP Server 500 错误返回到海报输出.当我将字符串作为 xml 返回时,我没有收到错误消息.这让我想知道是否需要在 Glassfish 的耳朵中放入任何 JAX-RS 罐或 Jersey 罐.我认为这些包含在 Glassfish 模块中,所以我没有将它们包含在我的 WEB-INF 库中.

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.

这是一个工作示例,将 xml 返回到 firefox 海报:

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>";

}

以下是引发内部服务器错误 500 的示例:

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;
   }
}

仅供参考 - 我正在关注这里的博客 - restBlog

FYI - I am loosely following the blog here - restBlog

推荐答案

您绝对不需要在 war 或 ear 文件中包含任何标准的 jersey 文件,以便在运行时可以访问它们.无论是使用 maven 还是本机 netbeans 7.3.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.

我建议您查看 glassfish server.log 文件以准确了解您得到的详细错误是什么.如果您缺少所需的罐子,那应该会告诉您.

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.

这篇关于我是否需要在 Glassfish4.0 服务器上的 EAR 中包含 Jersey 罐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆