Sometimes you need to automate maintenance tasks in your Play application (e.g. import data from CSV file into your app’s database, generate a report…). To do anything useful you need the proper classpath and probably a connection to the database using the same infrastructure normally used by the application. This is very similar to how tests are run. In this post I will show how I created a Scripts object that takes care of the FakeApplication initialization to allow simple script creation and usage from the test:console.

## The Scripts object

Place a Scripts.scala file inside the test folder. This is required as the files inside this folder are compiled with a classpath that includes the play.api.test._ symbols.

## JogosCSVImporter

To minimize the code in the test folder place the JogosCSVImporter object inside the app/tools folder.

## Using scripts in the test:console

In the test:console you can call any Scripts.\_ without worring about the classpath or any context initialization.