How can I serve static content with Glassfish embedded?
Posted
by
Andy Fiedler
on Stack Overflow
See other posts from Stack Overflow
or by Andy Fiedler
Published on 2012-12-11T23:01:59Z
Indexed on
2012/12/11
23:03 UTC
Read the original article
Hit count: 211
java
|glassfish-embedded
I'm trying to setup Glassfish embedded with a WAR project that implements a REST API and then some static Javascript content that calls it. I got the WAR to deploy and the REST API is available with a context root of "/Users".
How can I use Glassfish to serve static content with a context root of "/". So for example, if the user requests http://myserver.com/Users/some-REST-call it routes to the WAR application and http://myserver.com/somefile.js serves a static file from some directory?
Here's my Main class file so far:
public class Main{
public static void main(String[] args) throws Exception {
String port = System.getenv("PORT");
port = port != null ? port : "8080";
GlassFishProperties gfProps = new GlassFishProperties();
gfProps.setPort("http-listener", Integer.parseInt(port));
GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(gfProps);
glassfish.start();
Deployer deployer = glassfish.getDeployer();
deployer.deploy(new File("target/Users-Rest.war"));
}
}
Thanks a ton for your help!
© Stack Overflow or respective owner