我用https://github.com/sbt/sbt-assembly构建我的scala项目,以获得一个fatjar。
项目的结构如下所示(您可以看到资源文件夹,其中包含一个文件SapConfig.json):

然后,我尝试执行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") 我应该把我的资源文件放在哪里?
发布于 2018-04-04 18:35:32
https://stackoverflow.com/questions/49629964
复制相似问题