5

GREAT START WITH PLAY FRAMEWORK

 2 years ago
source link: https://blog.knoldus.com/great-start-with-play-framework/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Reading Time: 2 minutes

In this blog, We’ll learn how to set up the Play Framework, we’re going to create our first project with the Play Framework using Scala. Additionally, we’ll examine its built-in testing capabilities.

Project Setup

We need to first install the sbt command-line tool (and at least JDK 8). In this blog, we’re using sbt version 1.6.2 to install Play Framework version 2.8.13.

Command-line Tools

We can create a new application by using the sbt new command. To create a new project using sbt you can run the following command:

sbt new playframework/play-scala-seed.g8

After loading of dependencies, the tool displays a prompt and asks us to name the new project and provide the organization name.

This template generates a Play Scala project
name [play-java-seed]: knoldus-play-framework
organization [com.example]: knoldus.com
play_version [2.8.13]: 2.8.13
scala_version [2.13.8]: 2.13.8
Template applied in /home/knoldus/./knoldus-play-framework

Now, we can run the project from the knoldus-play-framework directory:

cd knoldus-play-framework
sbt run

Now, we run the project and it may take a couple of minutes to load the dependencies, Once it is started, we can open the browser and enter the URL http://localhost:9000, Now you get the default welcome page:

Great, we have created a working HTTP server in the Play Framework using Scala without touching any code.

Project Structure

Now, it’s time to load the project code into the IDE(IntelliJ IDE) and look at the directory structure.

The project structure looks like this:

app                      → Application sources
 └ assets                → Compiled asset sources
    └ stylesheets        → Typically LESS CSS sources
    └ javascripts        → Typically CoffeeScript sources
 └ controllers           → Application controllers
 └ models                → Application business layer
 └ views                 → Templates
build.sbt                → Application build script
conf                     → Configurations files and other non-compiled resources (on classpath)
 └ application.conf      → Main configuration file
 └ routes                → Routes definition
dist                     → Arbitrary files to be included in your projects distribution
public                   → Public assets
 └ stylesheets           → CSS files
 └ javascripts           → Javascript files
 └ images                → Image files
project                  → sbt configuration files
 └ build.properties      → Marker for sbt project
 └ plugins.sbt           → sbt plugins including the declaration for Play itself
lib                      → Unmanaged libraries dependencies
logs                     → Logs folder
 └ application.log       → Default log file
target                   → Generated stuff
 └ resolution-cache      → Info about dependencies
 └ scala-2.13
    └ api                → Generated API docs
    └ classes            → Compiled class files
    └ routes             → Sources generated from routes
    └ twirl              → Sources generated from templates
 └ universal             → Application packaging
 └ web                   → Compiled web assets
test                     → source folder for unit or functional tests

app/ directory

The app directory contains three packages for each component of MVC(Model View Controller):

  • models
  • views
  • controllers

conf/ directory

The conf directory contains the project’s configuration files:

  • application.cpnf
  • routes

public/ directory

The public directory stores the resources of the application

  • images
  • CSS styslesheet
  • JavaScript files

build.sbt file

We’ll find project’s main build declarations are in build.sbt at the root of the project.

project/ directory

The project directory contains the sbt build definitions:

  • plugins.sbt
  • build.properties

Conclusion

Through this blog, You will get the basic knowledge about the Play framework, and also it provides us with a more concise and readable code. We explored how to set up the play framework.

for more details:- https://blog.knoldus.com/kick-start-to-a-play-framework/

Scala Future


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK