Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we completely avoid Scala and simply use the Play! framework

This is a total newbie question. Is it possible to use the Play! framework without having to use any Scala at all?

Even when I create a pure java app it seems to create the index.scala.html and uses the Scala @ syntax. Are there any samples of a pure Java app on the Play! site?

I dont want to spend time learning the syntax of Scala (however much the documentation reassures me that its "just like java"). So basically i would like the app stack to be HTML,CSS,Jquery and a solid java framework on the server with a db like mongo. Thats it.

If not Play! what (recent) framework could be used?

like image 540
Vijay Avatar asked Jun 12 '12 12:06

Vijay


People also ask

What is play framework in Scala?

Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.

Is Play framework asynchronous?

Internally, Play Framework is asynchronous from the bottom up. Play handles every request in an asynchronous, non-blocking way. The default configuration is tuned for asynchronous controllers.

Does Play support Scala 3?

Play Framework does not support Scala 3, as of August 2021.

Is play a Java Framework?

Play is a high-productivity web application framework for programming languages whose code is compiled and run on the JVM, mainly Java and Scala. It integrates the components and APIs we need for modern web application development.


1 Answers

If you are using Play 2, then yes you can work entirely in java: You can notice in the documentation, that you can generate response using scala this way

public static Result homePage() {
  return ok(views.html.index.render());
}

where "index" is some class generated from the internal scala templating engine. However, you can also write your own response, like this:

public static Result homePage() {
  return ok("<html><body>Hello world!</body></html>");
}

As you can see, you are not pushed here to use scala templating system. What the ok() method want, is the string which is then sent to the client (with HTML OK header). How you generate the HTML code is entirely on you. You can use scala template engine, you can generate this string purely by java code or you can write some wrapper and use some totally different library.

So the answer is: yes, you do not have to use scala at all.

See examples of play 2 controllers without scala

But I strongly advice you to use at least some templating system...

like image 162
Břetislav Wajtr Avatar answered Sep 23 '22 18:09

Břetislav Wajtr