如何从jar运行泽西服务器(eclipse)

时间:2013-03-14 17:20:17

标签: java jersey

我用泽西开发了一个小型服务器

HttpServer server = HttpServerFactory.create("http://localhost:9998/");
server.start();

和这样的小api:

@GET
@Path("serverconnectiontest")
@Produces(MediaType.APPLICATION_JSON)
public CommunicationResponseM isDatabaseOnline()
{
    CommunicationResponseM result = new CommunicationResponseM();


    return result;
}
如果我用right_click->运行as-> java应用程序启动服务器,那么在eclipse中

一切顺利,所以如果我在网络浏览器中键入路径,我可以看到服务器响应..

现在我想制作一个服务器的jar,所以我这样做: right_click-> export-> runanble_jar我得到jar文件..但是如果我使用“java -jar file.jat”运行这个jar,服务器没有响应并给我这个错误:

com.sun.jersey.spi.container.ContainerResponse write
SEVERE: A message body writer for Java class
it.unitn.se.gym.backend.models.CommunicationResponseM, and Java type class 
it.unitn.se.gym.backend.models.CommunicationResponseM, and MIME media type
application/json was not found

Mar 14, 2013 6:59:10 PM com.sun.jersey.spi.container.ContainerResponse write

SEVERE: The registered message body writers compatible with the MIME media type are:
application/json -> 
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$App
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$App
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$App

com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter
com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$General
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$General
com.sun.jersey.json.impl.provider.entity.JSONWithPaddingProvider
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy

Mar 14, 2013 6:59:10 PM com.sun.jersey.spi.container.ContainerResponse logException
SEVERE: Mapped exception to response: 500 (Internal Server Error)
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body     
writer for Java class it.unitn.se.gym.backend.models.CommunicationResponseM, and Java type   
class it.unitn.se.gym.backend.models.CommunicationResponseM, and MIME media type   
application/json was not found
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:285)
at    

   com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1479)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
at com.sun.jersey.server.impl.container.httpserver.HttpHandlerContainer.handle(HttpHandlerContainer.java:191)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:65)
at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:65)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:68)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:557)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:65)
at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:529)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)
 Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class    
it.unitn.se.gym.backend.models.CommunicationResponseM, and Java type class     
it.unitn.se.gym.backend.models.CommunicationResponseM, and MIME media type   
application/json was not found
你可以帮帮我吗?

很多事情发生了!

如果我尝试

1 个答案:

答案 0 :(得分:0)

您是否配置了指向要运行的Main类的MANIFEST.MF文件?更多信息here