Java Grizzly jersey中的静态内容

Java Grizzly jersey中的静态内容,java,jersey,grizzly,Java,Jersey,Grizzly,我想在/and/index.html中提供静态html页面 final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc); 基本URL= 我的问题是静态文件应该放在哪里?在您的情况下,静态数据应该位于磁盘根目录中的/static文件夹中 静态资源的位置有两个选项: 您可以通过绝对路径(例如/www/static/)从文件系统提供静态资源: 或者将您的资源嵌入jar存

我想在/and/index.html中提供静态html页面

final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
基本URL=


我的问题是静态文件应该放在哪里?在您的情况下,静态数据应该位于磁盘根目录中的
/static
文件夹中

静态资源的位置有两个选项:

  • 您可以通过绝对路径(例如
    /www/static/
    )从文件系统提供静态资源:

  • 或者将您的资源嵌入jar存档(例如
    /www/static.jar
    ):

  • 或者在应用程序jar中嵌入静态资源:

    StaticHttpHandler staticHttpHandler = new CLStaticHttpHandler(YourApp.class.getClassLoader());
    server.getServerConfiguration().addHttpHandler(staticHttpHandler, "/");
    
StaticHttpHandler staticHttpHandler = new StaticHttpHandler("/www/static/");
server.getServerConfiguration().addHttpHandler(staticHttpHandler, "/");
StaticHttpHandler staticHttpHandler = new CLStaticHttpHandler(new URLClassLoader(new URL[] {new URL("file:///www/static.jar")}));
server.getServerConfiguration().addHttpHandler(staticHttpHandler, "/");
StaticHttpHandler staticHttpHandler = new CLStaticHttpHandler(YourApp.class.getClassLoader());
server.getServerConfiguration().addHttpHandler(staticHttpHandler, "/");