【发布时间】:2014-07-06 10:33:11
【问题描述】:
在我的 pom.xml 中添加一个依赖项。
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>2.10.1</version>
</dependency>
代码主要部分:
public static void main(String[] args) {
final URI baseUri = UriBuilder.fromUri("http://localhost").port(9998).build();
//add test configs
Set rest = new HashSet<Class>();
rest.add(TestResource.class);
final ResourceConfig config = new ResourceConfig(rest);
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);
try {
//server.getServerConfiguration().addHttpHandler(new StaticHttpHandler("web/"),"/w");
server.getServerConfiguration().addHttpHandler(new StaticHttpHandler("src/main/resources/web"),"/");
server.start();
System.out.println();
System.out.println("Press enter to stop the server...");
System.in.read();
} catch (IOException e) {
e.printStackTrace();
} finally {
server.shutdownNow();
}
}
这种情况下,API 不工作,但部署到“/”的静态 Web 工作正常。 Please check this screen.
然后当我更改几行代码时:
server.getServerConfiguration().addHttpHandler(new StaticHttpHandler("src/main/resources/web"),"/www");
API 和静态网络正在运行,但网络不在“/”,而是在“/www”。 Please check this.
你能帮我在“/api”获得有效的API,在“/”获得静态网络吗?
【问题讨论】:
标签: java maven jersey jax-rs grizzly