Search code examples
scalaplayframeworkroutesplayframework-2.0static-resource

Scala Play framework - cannot find static resources


I am new to Scala Play Framework. In my routes I have mentioned my the url to all my static resources. Here is the code for it.

GET    /public/*file    controllers.Assets.at(path="/public/", file)

My application context is /api/dashboard/v2.2. I have a public folder in the root of my project. There is an html page called default.htm. Now I want to see the html page in the browser.

In the url I am typing http://localhost:9000/api/dashboard/v2.2/public/default.htm. It is giving me 404 Not Found error. The call to the methods of the controller are working fine. But whenever I am trying to call the static resources I am getting this error.


Solution

  • Make an Route in your route file located at conf/route

    add a route default route.

    GET          /yoururl              controllers.Application.default
    

    Move your file to views folder and save it as default.scala.html.

    Make a controller Application controller in your controller folder.

    import play.api.mvc._
    object Application extends Controller {
    
      def default = Action {
        Ok("views.html.default()")
      }
    
    }
    

    Type In Browser "http://localhost:9000/yoururl" It will render your default HTML page.