I'm currently working with the Play Framework and have encountered an issue with starting the H2 database browser. Here's the background:
Previous Setup:
sbt
h2-browser
run
Switched to IntelliJ:
H2 Browser Configuration:
Adding H2 Dependency:
build.sbt
file as follows:
libraryDependencies += "com.h2database" % "h2" % "2.1.214"
lazy val startH2Browser = taskKey[Unit]("Starts the H2 Browser")
startH2Browser := {
println("Starting H2 Browser...")
org.h2.tools.Server.createWebServer("-web", "-webAllowOthers", "-webPort","8082").start()
}
playRunHooks += {
new play.sbt.PlayRunHook {
override def beforeStarted(): Unit = {
startH2Browser.value
}
}
}
Encountered Error:
build.sbt:55: error: object h2 is not a member of package org
org.h2.tools.Server.createWebServer("-web", "-webAllowOthers", "-webPort", "8082").start()
^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
Confirmation of H2 Package:
Can someone please advise me on how to properly import the H2 dependency in the build.sbt
file and resolve this issue?
by forking sbt command process and running h2-browser
lazy val startH2Browser = taskKey[Unit]("Starts the H2 Browser")
startH2Browser := {
println("Starting H2 Browser...")
Command.process("h2-browser",state.value)
}
playRunHooks += {
new play.sbt.PlayRunHook {
override def beforeStarted(): Unit = {
startH2Browser.value
}
}
}