2

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"));
    }
}

P.S. I'm aware that ideally you'd use Apache to serve the static content, however, I'm using Glassfish embedded to try to deploy to Heroku. Thanks a ton for your help!

Andy Fiedler
  • 513
  • 1
  • 5
  • 8

0 Answers0