6

我正在对 Play Subproject 功能进行更多扩展测试,如下所述:http ://www.playframework.com/documentation/2.0/SBTSubProjects 。但我收到错误:

Assets is already defined as object Assets

托管在 github 上的示例应用程序:https ://github.com/adis-me/PlayStrap

我已经为我的子项目定义了一个资产控制器,如下所述:资产控制器描述,即使是主项目,但错误不断弹出。我的项目有什么问题?

控制器

package com.company.playstrap.controllers;

import controllers.AssetsBuilder;

public class Assets {

    public static controllers.AssetsBuilder delegate = new AssetsBuilder();

}

路由文件

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET     /                               com.company.playstrap.controllers.Application.index()

# Include sub projects
-> /common                              common.Routes
-> /admin                               admin.Routes
-> /website                             website.Routes

# Map static resources from the /public folder to the /assets URL path
GET     /assets/*file                   com.company.playstrap.controllers.Assets.delegates.at(path="/public", file)
4

2 回答 2

5

这是一个已知的错误:https ://groups.google.com/forum/#!msg/play-framework/2Zk5wjAlIng/Jcec1lt7AzQJ

我自己的管理模块的解决方法:

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)
于 2013-04-02T13:46:43.033 回答
1

上周我在尝试将 Assets 类编写为 Java 类时遇到了这个问题。我可以解决在我的子模块中将 Assets 类编写为 Scala 类的编译问题,与文档中描述的方式相同:http ://www.playframework.com/documentation/2.1.1/SBTSubProjects

基本上,我的项目结构是:

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


Assets.scala内容:

package controllers.contabil

object Assets extends controllers.AssetsBuilder 


最后,我的admin.routes文件的内容是:

GET     /assets/*file    controllers.admin.Assets.at(path="/public", file)

# Home page
GET     /index           controllers.admin.Application.index() 


干杯

于 2013-05-14T03:06:40.840 回答