How to deploy PlayFramework Project with H2-Database

74 views
Skip to first unread message

roth.st...@gmail.com

unread,
Nov 23, 2017, 1:27:31 PM11/23/17
to Play Framework
I developed my first PlayFramework project, which used the H2-Database. While developing I did this to start the application:

- ./activator

- h2-browser

- run


So I accessed the database via the browser GUI. The first time I filled the database with values, after that I only started it so I could get access to the data once the application runs.

Now I want to deploy my application, for example on google app engine. So obviously I have to start the database and fill it with the data once on the server. But how can I do that on the server? Can someone explain this to me? Sorry if thats a stupid question, but I am still learning :).

Thanks in advance

Jamiel Sheikh

unread,
Nov 23, 2017, 2:50:27 PM11/23/17
to play-fr...@googlegroups.com
You can load a YAML file on startup

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/c06ff76e-25c7-49c9-8a46-aa0ea5b51665%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Will Sargent

unread,
Nov 24, 2017, 12:18:48 PM11/24/17
to play-fr...@googlegroups.com
You can start the database and fill it with data (or do anything, really) by adding things to the module and running through it.

For example, you can add a FlywayMigrator class:


and then bind it and run it in production:

package modules

class FlywayModule extends Module {
  override def bindings(environment: Environment, configuration: Configuration): Seq[Binding[_]] = {
    Seq(bind[FlywayMigrator].toSelf.eagerly() )
  }
}

by adding the module to application.conf:

play.modules.enabled += "modules.FlywayModule"

See 


Will Sargent

unread,
Nov 24, 2017, 12:21:09 PM11/24/17
to play-fr...@googlegroups.com
Also, I noticed you're using ./activator -- the latest version of play don't use activator, but use SBT directly.

You can see and download all the examples (with lots of database related examples) here:

roth.st...@gmail.com

unread,
Nov 24, 2017, 8:08:17 PM11/24/17
to Play Framework
I see. So then it starts the database when the application gets called right. Is there also a Java example for it?

Also I found that I can start the h2-browser from the command line and run a sql script from there as well, which would be perfect. Then I would only have to start it once and run the script once on the server. 
But there's a strange thing happening. When I start the H2-Database from the Terminal, and then I start my application the way I did it all the time, just without the h2-browser command, the application never loads for some reason. When I try to go to localhost:9000 it just never loads the page. I have no idea why though.



To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages