关于scala:Sbt dist是否导致无法访问非托管资源?

Sbt dist cause no access to unmanaged resources?

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

我的问题在这里。

运行sbt时,我可以通过添加

来访问非托管资源

1
unmanagedResourceDirectories in Assets += baseDirectory.value /"works"

到我的build.sbt

但是,在sbt dist之后,相同的网址不再起作用,并向我发送404 not found错误。

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

此" works"文件夹包含将在服务期间生成的文件,该文件与通常的" public"文件夹是分开的目录。

这是我的路线供参考。

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

sbt-dist是否需要build.sbt中的任何其他代码,或者我应该解决什么问题?


好的,这就是我解决问题的方法。
经过数小时(可能数天)的研究,我能够通过在控制器sendfile(new file(filename), inline=true)

中添加新功能来访问外部文件

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

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


通过unmanagedResourceDirectories

指定的其他资产目录

1
unmanagedResourceDirectories in Assets += baseDirectory.value /"works"

根据文档,

也将从public中投放:

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路线

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

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

现在应该可以同时访问两个其他资产

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

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

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