Where do I put startup code in Play Framework?

You need to create a bootstrap job which will be executed by Play at application start time.

@OnApplicationStart
public class Bootstrap extends Job {

    public void doJob() {
       //do stuff
    }    
}

Read more about how to do this in the Play Manual.


For playframework 2.6+, please refer to playframework doc: Eager bindings

For playframework 2.0 to 2.5, use GlobalSettings, as the following code:

import play.*;

public class Global extends GlobalSettings {

  @Override
  public void onStart(Application app) {
    Logger.info("Application has started");
  }  

  @Override
  public void onStop(Application app) {
    Logger.info("Application shutdown...");
  }  
}

more information, go to playframework docs: JavaGlobal