我正在尝试使用以下代码运行我的第一个Restlet服务器:
import org.restlet.Server;
import org.restlet.data.Protocol;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
public class WebServer extends ServerResource {
/**
* @param args
* @throws Exception
*/
public WebServer() throws Exception {
// Create the HTTP server and listen on port 8182
Server server = new Server(Protocol.HTTP, 8182, WebServer.class);
server.start();
}
@Get
public String present() {
return "hello, world";
}
}
但是当我启动服务器时,收到此错误消息:
No available server connector supports the required protocols: 'HTTP' . Please add the JAR of a matching connector to your classpath. Then, register this connector helper manually.
我将“org.restlet.jar”复制到\ libs文件夹,并将JAR添加到Java Build Path中的Libraries。我该怎么办?有什么问题?
答案 0 :(得分:3)
如果将其配置为使用NIO HttpServerHelper,则可以运行它。只需下载NIO扩展并在RestLet引擎中进行配置,您就可以再次启动HTTP服务器。 (经2.3.1测试)。
import org.restlet.ext.nio.HttpServerHelper;
...
Engine.getInstance().getRegisteredServers().clear();
Engine.getInstance().getRegisteredServers().add(new HttpServerHelper(null));
要查看NIO扩展程序是否适用于您的版本,您可以查看: http://restlet.com/technical-resources/restlet-framework/guide/2.3/extensions/editions-matrix