Scala and sbt: Storing SQL in a resource

寵の児 提交于 2019-12-21 23:00:26

问题


I'd like to store a database schema in its own file, and have my Scala code retrieve it (and execute it via JDBC).

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.

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?


回答1:


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" );



回答2:


Why don't you generate a file, and store it as "my.sql", and later search for it, where it appears in the filesystem?



来源:https://stackoverflow.com/questions/4832751/scala-and-sbt-storing-sql-in-a-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!