gpt4 book ai didi

java - 在制作过程中获取 Play Framework 中的根文件夹?

转载 作者:行者123 更新时间:2023-11-30 03:13:08 25 4
gpt4 key购买 nike

我正在开发一个项目,我必须在文件系统上保存一些临时用户生成的文件。在我的开发环境中,我在根文件夹中创建了一个名为 usr 的文件夹,并创建了从该文件夹读取和写入的用户相对路径。

但是,当我使用 /.activator start 在生产环境中运行服务器时。框架尝试从 root/target/universal/stage/usr 读取。

我什至尝试使用Play.application.path.getPath,但我一直得到相同的路径。

有没有办法在生产中获取根文件夹?

谢谢

最佳答案

您正在获取正确的根文件夹。 start 命令的意义是验证您的应用程序将如何在生产环境中运行。因此它会构建应用程序,就像您将其推送到产品时所做的那样。然后“将其部署到产品” - 将其解压到 target/universal/stage 文件夹并从该文件夹运行应用程序。所以 target/universal/stage 是您正确的根文件夹。

请注意 - 启动命令已弃用:

[warn] The start command is deprecated, and will be removed in a future version of Play.

[warn] To run Play in production mode, run 'stage' instead, and then execute the generated start script in target/universal/stage/bin.

[warn] To test your application using production mode, run 'testProd' instead.

更新

您需要添加到build.sbt下一个代码

mappings in Universal ++=
(baseDirectory.value / "usr" * "*" get) map
(x => x -> ("usr/" + x.getName))

这会告诉 sbt 将“usr”文件夹添加到“生产包”(阶段)。请注意 - 它不会“链接”,它会将 usr 文件夹硬复制到 target/universal/stage,因此您将拥有 target/universal/stage/usr 是运行命令 start

之前的 usr 的副本

关于java - 在制作过程中获取 Play Framework 中的根文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33223572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com