如何确定fatjar的资源?

时间:2018-04-03 12:20:12

标签: scala jar sbt

我使用https://github.com/sbt/sbt-assembly构建我的scala项目以获得一个胖子 项目结构如下(您可以看到包含文件SapConfig.json的resources文件夹):
enter image description here

然后,我尝试按如下方式执行fatjar:

java -jar SapEvents-assembly-0.1.0.jar 
java.nio.file.FileSystemNotFoundException
        at com.sun.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:171)
        at com.sun.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:157)
        at java.nio.file.Paths.get(Paths.java:143)
        at ch.micarna.SapEventServer$.stream(SapEventServer.scala:22)
        at ch.micarna.SapEventServer$.stream(SapEventServer.scala:16)
        at fs2.StreamApp.$anonfun$runStream$1(StreamApp.scala:66)
        at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:128)
        at cats.effect.internals.IORunLoop$.start(IORunLoop.scala:35)
        at cats.effect.IO.unsafeRunAsync(IO.scala:257)
        at cats.effect.IO.$anonfun$runAsync$1(IO.scala:175)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at cats.effect.internals.IORunLoop$.step(IORunLoop.scala:167)
        at cats.effect.IO.unsafeRunTimed(IO.scala:304)
        at cats.effect.IO.unsafeRunSync(IO.scala:239)
        at fs2.StreamApp.main(StreamApp.scala:83)
        at ch.micarna.SapEventServer.main(SapEventServer.scala)

您可以认识到,我认为无法找到资源文件 读取资源文件的代码如下所示:

Paths.get(getClass.getClassLoader.getResource("SapConfig.json")  

我应该把资源文件放在哪里?

1 个答案:

答案 0 :(得分:0)

我认为您的解决方案位于this post

仅更改

  

src / main / webapp到src / main / resources