Reputation: 7795
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.
Upvotes: 33
Views: 11320
Reputation: 63
Late answer, but for people who can encounter the same situation in 2022, This is possible with Play 2.8.x Scala doc, but is valid for Java too.
You can define your custom package com.test.controllers (even in the root App folder). You need after to define routes for it classes to match Reverse routing as stated in the documentation here.
For example, if you defined a class foo.java that has a method index that is accessible at endpoint /index, your routes file have to reflect it like this:
GET /index com.test.controllers.foo.index
And you can access it from the HTML file using helper (Reverse routing) like this:
@com.test.controllers.routes.foo.index()
Upvotes: 0
Reputation: 54924
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.
Upvotes: 7
Reputation: 407
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:
Upvotes: 21
Reputation: 274738
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
.
Upvotes: 13