如何在Play Framework 2.3.2中拥有多个/public目录? [英] How to have more than 1 /public directory in Play Framework 2.3.2?

查看:89
本文介绍了如何在Play Framework 2.3.2中拥有多个/public目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将应用程序从Play 1.2.7迁移到Play 2.3.2.

We are migrating an app from Play 1.2.7 to Play 2.3.2.

由于我们之前已将大部分Play 1.2.7应用程序从Backbone迁移到AngularJS,因此在1.2.7中最终得到了两个这样的静态资产目录:

Because we had previously migrated most of our Play 1.2.7 app from Backbone to AngularJS, we ended up with two static asset directories like this in 1.2.7:

/public -- contains Backbone scripts/templates
/platform/app -- contains AngularJS scripts/templates

我正在尝试并行迁移而不破坏1.2.7代码,所以我有类似的东西,因此我可以在/app中重写Java控制器,并使用现有的JavaScript/HTML资产:

I'm trying to do the migration side-by-side without breaking the 1.2.7 code, so I have something like this, so I can just rewrite the Java controllers in /app, and use the existing JavaScript/HTML assets:

~/play1/app
~/play1/public
~/play1/platform/app

~/play2/app
~/play2/public (symlink to ../../play1/public)
~/play2/platform (symlink to ../../play1/platform)

当我执行激活程序运行时,即使我有它们的路由,也无法访问/play2/platform中的文件.查看它,这些文件都没有被复制到〜/play2/target/public,因此controller.Assets找不到它们.在Play/SBT中有什么方法可以做到这一点?

When I do an activator run, the files in /play2/platform are not accessible even though I have a route for them. Looking into it, none of those files get copied into ~/play2/target/public, so controller.Assets doesn't find them. Is there a way within Play/SBT to do this?

我认为我在构建发行版时可以以某种方式让脚本进行复制(我需要研究一下),但是我希望它可以用于交互式开发.

I assume I could somehow have a script do the copy when I build for distribution (I need to look into that), but I would like this to just work for interactive development.

这可能是补救措施,但是我是Play 2.x,Scala和SBT的新手,所以我还无法弄清楚.

This is probably remedial, but I'm new to Play 2.x, Scala, and SBT, so I haven't been able to figure it out yet.

谢谢

查尔斯

推荐答案

Play 2.3迁移指南在sbt-web部分中对此进行了讨论.

The Play 2.3 migration guide discusses this in the sbt-web section.

sbt-web的一个细微之处在于,所有资产都是从公用文件夹提供的.因此,如果您以前有资产位于公用文件夹之外,即按照以下示例使用playAssetsDirectories设置:

A nuance with sbt-web is that all assets are served from the public folder. Therefore if you previously had assets reside outside of the public folder i.e. you used the playAssetsDirectories setting as per the following example:

playAssetsDirectories< + = baseDirectory/"foo" …那么您现在应该使用以下内容:

playAssetsDirectories <+= baseDirectory / "foo" …then you should now use the following:

资产中的unmanagedResourceDirectories + = baseDirectory.value/"foo"

unmanagedResourceDirectories in Assets += baseDirectory.value / "foo"

当我将其添加到Play Java项目的根目录下的build.sbt时,这对我有用:

This worked for me when I added to this to build.sbt in the root of my Play Java project:

unmanagedResourceDirectories in Assets += baseDirectory.value / "platform/app"

这篇关于如何在Play Framework 2.3.2中拥有多个/public目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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