Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anyone successfully deployed a GWT app on Heroku?

Tags:

heroku

gwt

Heroku recently began supporting Java apps. Looking through the docs, it seems to resemble the Java Servlet Standard. Does anyone know of an instance where a GWT app has been successfully deployed on Heroku? If so, are there any limitations?

like image 462
Travis Webb Avatar asked Sep 10 '11 04:09

Travis Webb


2 Answers

My first answer to this turned out to have problems when GWT tried to read its serialization policy. In the end I went for a simpler approach that was less Guice-based. I had to step through the Jetty code to understand why setBaseResource() was the way to go - it's not immediately obvious from the Javadoc.

Here's my server class - the one with the main() method that you point Heroku at via your app-assembler plugin as per the Heroku docs.

public class MyServer {

public static void main(String[] args) throws Exception {
    if (args.length > 0) {
        new MyServer().start(Integer.valueOf(args[0]));
    }
    else {
        new MyServer().start(Integer.valueOf(System.getenv("PORT")));
    }
}

public void start(int port) throws Exception {

    Server server = new Server(port);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setBaseResource(createResourceForStatics());
    context.setContextPath("/");
    context.addEventListener(new AppConfig());
    context.addFilter(GuiceFilter.class, "/*", null);
    context.addServlet(DefaultServlet.class, "/");
    server.setHandler(context);

    server.start();
    server.join();
}

private Resource createResourceForStatics() throws MalformedURLException, IOException {
    String staticDir = getClass().getClassLoader().getResource("static/").toExternalForm();
    Resource staticResource = Resource.newResource(staticDir);
    return staticResource;
}
}

AppConfig.java is a GuiceServletContextListener.

You then put your static resources under src/main/resources/static/.

like image 173
MattR Avatar answered Oct 02 '22 23:10

MattR


In theory, one should be able to run GWT using the embedded versions of Jetty or Tomcat, and bootstrap the server in main as described in the Heroku Java docs.

like image 34
Travis Webb Avatar answered Oct 02 '22 23:10

Travis Webb