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:
Assets is already defined as object Assets
Sample application hosted on github: https://github.com/adis-me/PlayStrap
I have defined an Asset controller for my subprojects as described here: Asset Controller description, even for the main project, but the error keeps popping up. What is wrong with my project?
Controller
package com.company.playstrap.controllers;
import controllers.AssetsBuilder;
public class Assets {
public static controllers.AssetsBuilder delegate = new AssetsBuilder();
}
Routes file
# 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)
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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With