Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework: How to change play default packages?

I was just wondering if it is possible to change the default packages from Play. For example: I want to change the "controllers" package to "com.test.controllers". I don't know if this makes any sense, but I just want to know how if it is possible. I did not find anything related to this in play website.

like image 908
Alan Souza Avatar asked Jan 27 '11 12:01

Alan Souza


People also ask

What are Play Modules?

A Play module is a class that extends play.

Is Play Framework popular?

In July 2015, Play was the 3rd most popular Scala library in GitHub, based on 64,562 Libraries. 21.3% of the top Scala projects used Play as their framework of choice. As of October 2013, the Play Framework is the most popular Scala project on GitHub.

What is activator in play framework?

The activator command can be used to create a new Play application. Activator allows you to select a template that your new application should be based off. For vanilla Play projects, the names of these templates are play-scala for Scala based Play applications, and play-java for Java based Play applications.

How do I run the play framework in Java?

To run the Play framework, you need Java 6 or later. If you wish to build Play from source, you will need the Git source control client to fetch the source code and Ant to build it. Play will use the default Java or the one available at the $JAVA_HOME path if defined. The play command line utility uses Python.

How to build a Play Framework application using sbt?

The Play Framework documentation promises us “a powerful console and build tools”. We can start by generating the scaffolding of a new Play Framework application using sbt: After loading a lot of dependencies, the tool displays a prompt and asks us to name the new project and provide the organization name.

What is the controllers directory in Play Framework?

The controllers directory is where we will store our Scala code The views directory is where we’ll save our HTML templates The conf directory contains our router configuration which maps a request URL to a specific class and method Finally, the public directory contains the static content served by the Play Framework server

How to create a scaffolding for a Play Framework application?

We can start by generating the scaffolding of a new Play Framework application using sbt: After loading a lot of dependencies, the tool displays a prompt and asks us to name the new project and provide the organization name.


1 Answers

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.
like image 127
Sam Avatar answered Sep 19 '22 18:09

Sam