我想将数据库模式存储在自己的文件中,让我的Scala代码检索它(并通过JDBC执行)。
I'd like to store a database schema in its own file, and have my Scala code retrieve it (and execute it via JDBC).
似乎我,sbt要我将文件存储为:src / main / resources / packagename / my.sql。把它放在那里,我看到它在jar中 - 但我似乎无法从Scala访问它。
It seems to me that sbt wants me to store the file as: src/main/resources/packagename/my.sql. Putting it there, I see it's in the jar - but I can't seem to access it from Scala.
具体来说,getClass()。getResource(my.sql )返回一个空指针,我能想到的任何其他形式也是如此。
Specifically, getClass().getResource("my.sql") returns a null pointer, and so does any other form I can think of.
我应该如何加载文件?或者有更好的方法吗?
How should I load the file? Or is there a better way to do it?
推荐答案我有一个几乎相同的问题。 唯一的区别是我的文件位于 src / main / resources (没有任何包)。 这对我有用。
I had an almost identical problem. The only difference is my file is in src/main/resources (without any packages). This worked for me.
val is:InputStream = Github.getClass().getResourceAsStream( "/repo.json" );更多推荐
Scala和sbt:在资源中存储SQL
发布评论