简体   繁体   English

如何在不引用绝对路径的情况下引用播放框架第三方模块?

[英]How do I reference play framework third party modules without referencing an absolute path?

Here is my situation. 这是我的情况。 I have a play app which uses the guice module . 我有一个使用guice模块的播放应用程序。 In order to work with the guice module: 为了使用guice模块:

  • I installed it using play install guice . 我用play install guice安装它。 This installs it in the $PLAY_HOME/modules which is fine by me. 这将它安装在$PLAY_HOME/modules ,这对我来说很好。 I don't want to edit the module files in any way whatsoever. 我不想以任何方式编辑模块文件。
  • Then I declared the module in my dependencies.yml like so: - play -> guice 1.2 然后我在我的dependencies.yml声明了这个模块: - play -> guice 1.2
  • Within my app, I ran play dependencies , and this resoles the module just fine and creates a modules/guice-1.2 file that references the guice module. 在我的应用程序中,我运行了play dependencies ,这可以很好地恢复模块并创建一个引用guice模块的modules/guice-1.2文件。

The issue is that the content of that file is something like the following: /some-absolute-path/play-1.2.x/modules/guice-1.2 . 问题是该文件的内容类似于以下内容: /some-absolute-path/play-1.2.x/modules/guice-1.2

That works fine when working locally for development. 在本地开发工作时,这很好。 But when I want to move to a production server, with a different install of Play! 但是,当我想转移到生产服务器时,使用不同的Play安装! (ie with a different absolute path to it) it will obviously fail. (即使用不同的绝对路径)它显然会失败。

So what's the best way to deal with this? 那么解决这个问题的最佳方法是什么?

For now I've resorted to declaring the module in the application.conf file like this: module.guice=${play.path}/modules/guice-1.2 . 现在,我已经在application.conf文件中声明了这样的模块: module.guice=${play.path}/modules/guice-1.2 Unfortunately the ${play.path} magic doesn't seem to work on those generated files. 不幸的是, ${play.path}魔法似乎不适用于那些生成的文件。

By the way I use version 1.2.3 of Play! 顺便说一句,我使用Play版本1.2.3!

you should try with ${application.path} in your dependencies.yml file, like in this example 您应该在dependencies.yml文件中尝试使用$ {application.path},就像在此示例中一样

require:
    - play -> crud
    - provided -> DateHelper 1.0 
repositories: 
    - provided: 
        type:       local 
        artifact:   "${application.path}/jar/[module]-[revision].jar" 
        contains: 
            - provided -> * 

see this question: How can I specify a local jar file as a dependency in Play! 看到这个问题: 如何在Play中将本地jar文件指定为依赖项! Framework 1.x 框架1.x

It's not answer to your question, but I have faced with same issue. 这不是你的问题的答案,但我遇到了同样的问题。

  • I don't want to call resync the dependencies on production. 我不想调用resync对生产的依赖。
  • I don't want to ask my team members, install special module. 我不想问我的团队成员,安装特殊模块。
  • I don't want to commit file containing absolute path with module location. 我不想提交包含模块位置的绝对路径的文件。

The only workaround that I find: do not install module in Play! 我找到的唯一解决方法:不要在Play中安装模块! application, just include jars which use this module manually. 应用程序,只包括手动使用此模块的jar。 play-guice.jar should be included as @opensas suggested, aopalliance and com.google.inject as regular dependencies in dependencies.yml. play-guice.jar应作为@opensas建议, aopalliancecom.google.inject包含在dependencies.yml中作为常规依赖项。

The funny thing, that resync dependencies is also deleting .svn files, so back-up its before calling this command. 有趣的是,resync依赖项也删除.svn文件,所以在调用此命令之前备份它。

When you run in production you will either resync the dependencies (via play deps command) with the local installation of Play or in some scenarios you can precompile everything and then there will be no issues with the paths. 当您在生产中运行时,您将重新同步依赖项(通过play deps命令)与Play的本地安装,或者在某些情况下,您可以预编译所有内容,然后路径就不会出现问题。

That second scenario is the one with Heroku, for example. 例如,第二个场景是Heroku的场景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM