Play Framework: How to change play default packages?

Updated to make the distinction between play1 and 2 clear.

For Play 1.x, this is not possible.

No, all controllers must be in a package, or sub package of controllers. If you wanted to keep a com.test package structure, you can do controllers.com.test

For more info, see this thread.

For Play2.x, this is possible. Just move everything to the package you desire. Make sure that the outermost app/ directory stays at outside. An example would be play-project/app/com.company/controllers.

So the simple answer is...it depends, on whst version of Play you are using.


According to the current Play 2.0 documentation, this is now possible:

Note that in Play 2.0, the controllers, models and views package name conventions are now just that and can be changed if needed (such as prefixing everything with com.yourcompany).

This works well for an empty Play application, there are however some details to take note of for anything else:

  1. Importing custom namespaces into view templates will work for any types except for those that are declared in the first line of a template, which are the arguments for the scala render function that is generated out of a view. Our workaround is to add the full package name to type declarations in the first line of view templates.
  2. For every namespace defined in the routes file (e.g. a custom package and the default package for the Assets route), Play 2.0 generates a corresponding routes source file within the same namespace, so you need to take care to address the correct file when e.g. doing redirection.

From the manual:

A Controller class must be defined in the controllers package and must be a subclass of play.mvc.Controller.

You can add a Java package before the Controller class name if it isn’t defined directly under the controllers package. The controllers package itself is implicit, so you don’t need to specify it.

This means that you can't change your controllers package to com.test.controllers (because the root package must be controllers), but you can change to controllers.com.test.