クラスから Jetty サーバーを起動しようとしています。日食から実行しようとすると、正常に動作します。これを JAR に埋め込むと、jetty サーバーが起動しますが、リクエストを行うと 500 コードのレスポンスが返されます。これが私のクラスです:
@GET
@Path("test")
@Produces(MediaType.APPLICATION_JSON)
public String echo(@QueryParam("testParam")String test){
return test;
}
private Server server;
public synchronized void start(int port) throws Exception {
if (server != null) {
throw new IllegalStateException("Server is already running");
}
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
Map<String,Object> initMap = new HashMap<String, Object>();
initMap.put("com.sun.jersey.api.json.POJOMappingFeature", "true");
initMap.put("com.sun.jersey.config.property.packages", "the.class.package");
context.addServlet(new ServletHolder(new ServletContainer(new PackagesResourceConfig(initMap))), "/*");
this.server = new Server(port);
this.server.setHandler(context);
this.server.start();
}
public static void main(String[] args) throws Exception {
if(args.length != 1) {
System.out.println("AnnotatorServer <port>");
System.exit(-1);
}
JettyServer server = new JettyServer();
server.start(Integer.parseInt(args[0]));
}
JAR に埋め込まれて起動しようとすると、サーバーが起動しますが、メソッドにアクセスすると、次の例外が発生します。
Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class java.lang.String, and Java type class java.lang.String, and MIME media type application/octet-stream was not found
なぜこれが起こっているのか分かりますか?? ありがとうございました!