如何从 Play Framework 项目中创建可运行脚本?
How do I create a runnable script from within a Play Framework project?
我目前有一个游戏框架项目,其中包含大量代码(实用程序、模块等),我想在 运行nable 脚本(或 program/main)中使用这些代码。我的理解是,如果我将脚本设为子项目,那么我将无法使用父项目中的代码。我需要利用父项目中的代码。
我可以将脚本放在应用程序目录中的某个位置,然后执行类似 sbt 运行-main com.foo.bar.Foobar 之类的操作。不幸的是,这(显然)并没有引入所有的 Play。没有数据库,没有全局,没有配置等等等等。基本上它不 bootstrap 播放。
除了获取我的父项目并将我想共享的所有代码也制作成一个子项目之外,还有什么方法可以完成我正在尝试做的事情吗?
编辑:我尝试使用找到的解决方案 Here 但它会导致错误,指出没有应用程序 运行ning.
加上我找到的最好的解决方案‖How do I run a comand line scala script that uses Play Framework app database?(http://blog.felipe.rs/2014/05/14/run-maintenance-scripts-in-the-context-of-a-running-play-framework-application/)我只好按照下面的方式修改它。
def importJogosFromCSV(csvFilePath: String) = {
db withSession { implicit s: Session =>
JogosCSVImporter.importJogos(csvFilePath)
}
}
已更改为:
def importJogosFromCSV(csvFilePath: String) = {
running(application) {
db withSession { implicit s: Session =>
JogosCSVImporter.importJogos(csvFilePath)
}
}
}
最终我需要添加运行(应用程序)
我在 play 2 中使用 specs2。3.x
我目前有一个游戏框架项目,其中包含大量代码(实用程序、模块等),我想在 运行nable 脚本(或 program/main)中使用这些代码。我的理解是,如果我将脚本设为子项目,那么我将无法使用父项目中的代码。我需要利用父项目中的代码。
我可以将脚本放在应用程序目录中的某个位置,然后执行类似 sbt 运行-main com.foo.bar.Foobar 之类的操作。不幸的是,这(显然)并没有引入所有的 Play。没有数据库,没有全局,没有配置等等等等。基本上它不 bootstrap 播放。
除了获取我的父项目并将我想共享的所有代码也制作成一个子项目之外,还有什么方法可以完成我正在尝试做的事情吗?
编辑:我尝试使用找到的解决方案 Here 但它会导致错误,指出没有应用程序 运行ning.
加上我找到的最好的解决方案‖How do I run a comand line scala script that uses Play Framework app database?(http://blog.felipe.rs/2014/05/14/run-maintenance-scripts-in-the-context-of-a-running-play-framework-application/)我只好按照下面的方式修改它。
def importJogosFromCSV(csvFilePath: String) = {
db withSession { implicit s: Session =>
JogosCSVImporter.importJogos(csvFilePath)
}
}
已更改为:
def importJogosFromCSV(csvFilePath: String) = {
running(application) {
db withSession { implicit s: Session =>
JogosCSVImporter.importJogos(csvFilePath)
}
}
}
最终我需要添加运行(应用程序) 我在 play 2 中使用 specs2。3.x