Assets is already defined as object Assets

后端 未结 2 1783
执笔经年
执笔经年 2020-12-18 06:06

I am doing more extended tests for Play Subproject feature as described here: http://www.playframework.com/documentation/2.0/SBTSubProjects. But I am getting the error:

相关标签:
2条回答
  • 2020-12-18 06:52

    It is a known bug: https://groups.google.com/forum/#!msg/play-framework/2Zk5wjAlIng/Jcec1lt7AzQJ

    My workaround for an own admin module:

    package controllers.admin;
    import controllers.AssetsBuilder;
    import play.api.mvc.AnyContent;
    import play.api.mvc.Action;
    import play.mvc.*;
    
    public class Application extends Controller {
    
        private static AssetsBuilder delegate = new AssetsBuilder();
    
        public static Action<AnyContent> asset(String path, String file) {
            return delegate.at(path, file);
        }
    
    }
    
    //routes file
    GET /assets/*file   controllers.admin.Application.asset(path="/public", file)
    
    0 讨论(0)
  • 2020-12-18 07:02

    I faced this problem last week when I was trying to write the Assets class as a Java class. I could solve the compilation problem writing the Assets class in my submodule as a Scala class, the same way as described on the docs: http://www.playframework.com/documentation/2.1.1/SBTSubProjects

    Basically, my project's structure is:

    MyApplication
      | - app
      | - conf
      | - modules
            | - admin
                | - app
                    | - controllers
                        | - admin
                            | - Assets.scala
      | - project
      | - public
    


    Assets.scala content:

    package controllers.contabil
    
    object Assets extends controllers.AssetsBuilder 
    


    And finally, the content of my admin.routes file is:

    GET     /assets/*file    controllers.admin.Assets.at(path="/public", file)
    
    # Home page
    GET     /index           controllers.admin.Application.index() 
    


    Cheers

    0 讨论(0)
提交回复
热议问题