sbt dist 导致无法访问非托管资源?

Sbt dist cause no access to unmanaged resources?

对于我的 sbt - play/scala 应用程序,我在开发时一直在使用 sbt 运行。 几乎完成了我的项目,现在我想将 sbt dist 用于生产目的。 (如果这是个坏主意,请纠正我。)

我的问题在这里。

使用我的 sbt 运行,我可以通过添加

来访问非托管资源
unmanagedResourceDirectories in Assets += baseDirectory.value / "works"

给我的 build.sbt

然而,在 sbt dist 之后,相同的 url 不再有效并向我发送 404 not found 错误。

Not Found For request 'GET /assets/RAW/abc.png'

此 "works" 文件夹包含将在服务期间生成的文件,该文件夹与通常的 "public" 文件夹不同。

这是我的路线,仅供参考。

GET     /assets/*file               controllers.Assets.at(path="/public", file)
GET     /works/*file                controllers.Assets.at(path="/works/", file)

sbt-dist 是否需要 build.sbt 中的任何额外代码,或者我应该修复什么?

Additional asset directories 通过 unmanagedResourceDirectories

指定
unmanagedResourceDirectories in Assets += baseDirectory.value / "works"

也将从 public 根据 docs:

A nuance with sbt-web is that all assets are served from the public folder... note that the files there will be aggregated into the target public folder

这意味着您需要从

更改 GET /works 路线
GET     /works/*file                controllers.Assets.at(path="/works/", file)

GET     /works/*file                controllers.Assets.at(path="/public", file)

现在应该可以在两者上访问其他资产

http://example.com/assets/RAW/abc.png
http://example.com/works/RAW/abc.png

您可以通过在 .../target/universal 处解压缩生成的包,然后在 jar 下列出 jar 的内容,确认其他资产在 sbt dist 之后最终在 publiclib目录以-assets.jar结尾,例如:

jar tf target/universal/play-scala-starter-example-1.0-SNAPSHOT/play-scala-starter-example.play-scala-starter-example-1.0-SNAPSHOT-assets.jar

好的,这就是我解决问题的方法。 经过几个小时(可能是几天)的研究,我能够通过在控制器中添加一个新功能来访问外部文件,sendfile(new file(filename), inline=true)

我还必须设置路线。就我而言, GET /download/:id/:name controllers.DownloadTask.download(id: String, name: String)

在客户端中添加此 url/routes 信息后,效果很好。