user3641131
user3641131

Reputation: 31

Play Framework Java access public assets no method "at"

I am attempting I tried the following solution that I've found here:

controllers.routes.Assets.at("images/unchecked.png").absoluteURL(request())

but I am getting the following error :

cannot find symbol
  symbol:   method at(java.lang.String)
  location: variable Assets of type controllers.ReverseAssets

which looks like it cannot find the at method, which I thought was built in. Any thoughts?

Upvotes: 3

Views: 714

Answers (1)

Andriy Kuba
Andriy Kuba

Reputation: 8263

It's because you does not use "at" in the router, so it was not generated by Play.

I suppose you use versioned

GET     /assets/*file               controllers.Assets.versioned(path="/public", file: Asset)

Change it to the "at" in the "routes" file, then rebuild the project

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

EDIT:

You will need to go by some "special" way if you want to use versioned in the routes (better and recommended way). Play (2.3 and 2.4) have an issue in Java (Scala version is correct) so Assets.versioned(String file) version is not present, only Assets.versioned(Asset asset) is available. So there is "special" way:

"routes" file:

GET     /assets/*file               controllers.Assets.versioned(path="/public", file: Asset)

controller:

public Result index() {
    ...
    controllers.routes.Assets.versioned(toAsset("images/unchecked.png")).absoluteURL(request())
    ...    
}

public static controllers.Assets.Asset toAsset(String name) {
  return new controllers.Assets.Asset(name);
}

Look for an "Issue 3" in the Play 2.3.3 Bugs

Upvotes: 1

Related Questions