How can I serve static content with Glassfish embedded?
- by Andy Fiedler
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!