Scala和sbt:在资源中存储SQL [英] Scala and sbt: Storing SQL in a resource

查看:173
本文介绍了Scala和sbt:在资源中存储SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据库模式存储在自己的文件中,让我的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆