Is it possible to have both java and scala controllers and views in play framework project when the project is created with scala option?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it’s possible to mix Java and Scala in a Play application. You can mix both Java and Scala controllers and Groovy and Scala templates. The instructions below have been tested with Play! 1.2.2RC1.
I would start by keeping both your Java and Scala controllers in
app/controllers. Java is of course limited to one class per file, but in Scala packages are not tied to files and directories, so you can give your Scala file any name; as long as you declare the package correctly asPlay should have not trouble finding them.
Scala templates should end in
.scala.htmland Groovy templates in plain.html. In a Scala controller, you render Scala templates withhtml.templatenameand Groovy templates withTemplate("templatename").I have never tried rendering a Scala template from a Java controller, but I don’t see why it should not be feasible.
Finally, here’s a useful reminder on Scala/Java interop.