How to server static html from within a jar

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to server static html from within a jar

Macbeth, Andrew (US SSA)

I have a jersey REST app running with Grizzly. The app is jar’d up via maven. I have a static .html file that I want to be able to serve. The file is packaged into the root of the .jar file. I can’t figure out how to tell Grizzly to look into the jar file.

 

The root of the .jar file

/com

/META-INF

test.html

 

 

From main():

                              ResourceConfig resourceConfig = new PackagesResourceConfig("com.xyz.demo");

                              httpServer = GrizzlyServerFactory.createHttpServer(uri, resourceConfig);

                              StaticHttpHandler staticHttpHandler = new StaticHttpHandler("/");

                              httpServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/static");

 

From pom.xml:

                              <dependency>

                                             <groupId>com.sun.jersey</groupId>

                                             <artifactId>jersey-grizzly2</artifactId>

                                             <version>1.17</version>

                              </dependency>

 

 

Andrew J. Macbeth

 

Reply | Threaded
Open this post in threaded view
|

Re: How to server static html from within a jar

Ryan Lubke-2
That's currently not possible with the StaticHttpHandler.

I think it may be a useful feature, so I'd like to invite you to log an issue [1].

That said, you could also write your own HttpHandler to do this as a short term solution.  As long as your JAR is in the classpath when you start the server, your handler
would only need to call Thread.currentThread().getContextClassLoader().getResourceAsStream().

[1] http://java.net/jira/browse/GRIZZLY

February 14, 2013 8:11 AM

I have a jersey REST app running with Grizzly. The app is jar’d up via maven. I have a static .html file that I want to be able to serve. The file is packaged into the root of the .jar file. I can’t figure out how to tell Grizzly to look into the jar file.

 

The root of the .jar file

/com

/META-INF

test.html

 

 

From main():

                              ResourceConfig resourceConfig = new PackagesResourceConfig("com.xyz.demo");

                              httpServer = GrizzlyServerFactory.createHttpServer(uri, resourceConfig);

                              StaticHttpHandler staticHttpHandler = new StaticHttpHandler("/");

                              httpServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/static");

 

From pom.xml:

                              <dependency>

                                             <groupId>com.sun.jersey</groupId>

                                             <artifactId>jersey-grizzly2</artifactId>

                                             <version>1.17</version>

                              </dependency>

 

 

Andrew J. Macbeth