How to have more than 1 /public directory in Play

2019-09-07 19:59发布

问题:

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

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

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

and

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

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.

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.

Thanks,

Charles

回答1:

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

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" …then you should now use the following:

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

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"