Search code examples
playframeworksbtplayframework-2.3

Why does my web app not work after migration from 2.2.2 to 2.3.1?


Hello I have got big problem with Assets when I was migrating form play framework 2.2.2 to 2.3.1 version. Everything is working good except my class Assets. I was reading play migrate guide and was trying to do everything with this step by step but I still don't know how to do it.

I'm sorry for making very big post but I wanted to explain it as good as possible.

Before migration everything was wroking good, when I go into localhost:9000 I have written here (before I had my page)

Compilation error error: method at in class Assets cannot be applied to given types;

public class AssetsController extends Controller {

9    public static Action<AnyContent> at(String path, String file) {

10        return Assets.at(path, file); 

11    }

I get this Errors in terminal when running play ~debug

[warn] /home/myproject/NewProjectChange/workspace/play-angular/conf/routes:218: patterns
after a variable pattern cannot match (SLS 8.1.1)
[warn] If you intended to match against parameter file of method at, you must use 
backticks, like: case `file` =>
[warn] GET           /*file                                                   
controllers.Assets.at(path="/public", file)
[warn] /home/myproject/NewProjectChange/workspace/play-angular/conf/routes:18: unreachable code due to variable pattern 'file' on line 279
[warn] If you intended to match against parameter file of method at, you must use backticks, like: case `file` =>
[warn] GET           /login                                                  controllers.Assets.at(path="/public", file="login.html")
[warn] /home/myproject/NewProjectChange/workspace/play-angular/conf/routes:26: unreachable code due to variable pattern 'file' on line 279
[warn] If you intended to match against parameter file of method at, you must use backticks, like: case `file` =>
[warn] GET           /page/import                                            controllers.Assets.at(path="/public", file="import.html")
[warn] /home/myproject/NewProjectChange/workspace/play-angular/conf/routes:6: unreachable code due to variable pattern 'file' on line 279
[warn] If you intended to match against parameter file of method at, you must use backticks, like: case `file` =>
[warn] GET           /                                                       controllers.Assets.at(path="/public", file="index.html")
[warn] /home/myproject/NewProjectChange/workspace/play-angular/conf/routes:18: unreachable code
[warn] GET           /login                                                  controllers.Assets.at(path="/public", file="login.html")
[warn] 5 warnings found
[error] /home/myproject/NewProjectChange/workspace/play-angular/app/controllers/AssetsController.java:10: error: method at in class Assets cannot be applied to given types;
[error]         return Assets.at(path, file);
[error]                      ^
[error]   required: String,String,boolean
[error]   found: String,String
[error]   reason: actual and formal argument lists differ in length
[error] /home/myproject/NewProjectChange/workspace/play-angular/app/controllers/AssetsController.java:14: error: method at in class Assets cannot be applied to given types;
[error]         return Assets.at(path, file);
[error]                      ^
[error]   required: String,String,boolean
[error]   found: String,String
[error]   reason: actual and formal argument lists differ in length
[error] /home/myproject/NewProjectChange/workspace/play-angular/app/controllers/AssetsController.java:18: error: method at in class Assets cannot be applied to given types;
[error]         return Assets.at(path, file);
[error]                      ^
[error]   required: String,String,boolean
[error]   found: String,String
[error]   reason: actual and formal argument lists differ in length
[error] /home/myproject/NewProjectChange/workspace/play-angular/app/controllers/AssetsController.java:22: error: method at in class Assets cannot be applied to given types;
[error]         return Assets.at(path, file);
[error]                      ^
[error]   required: String,String,boolean
[error]   found: String,String
[error]   reason: actual and formal argument lists differ in length

My build.sbt file looks like:

name := "error"

version := "2.3.1"

lazy val root = (project in file(".")).enablePlugins(PlayJava,SbtWeb)

scalaVersion := "2.11.1"

crossScalaVersions := Seq("2.11.1", "2.10.4")

doc in Compile <<= target.map(_ / "none")

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
"com.typesafe.play.plugins" %% "play-plugins-util" % "2.3.0",
"com.typesafe.play.plugins" %% "play-plugins-mailer" % "2.3.0"
)

libraryDependencies += javaWs

libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.24"

libraryDependencies += "org.fusesource.scalate" % "scalate-core" % "1.5.3"

libraryDependencies += "net.sf.opencsv" % "opencsv" % "2.3"

libraryDependencies += "org.apache.thrift" % "libthrift" % "0.9.1"

libraryDependencies += "org.apache.httpcomponents" % "httpclient" % "4.2"

libraryDependencies += "org.apache.httpcomponents" % "httpcore" % "4.2"

libraryDependencies += "org.codehaus.jackson" % "jackson-core-asl" % "1.1.0"

libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.3.1"

And my plugins.sbt looks like:

// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// The Typesafe snapshot repository
resolvers += "Typesafe snapshots" at "http://repo.typesafe.com/typesafe/snapshots/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-webdriver" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.1")

And my Routes for example looks like:

# Map static resources from the /public folder to the /assets URL path
GET           /*file                                                  controllers.Assets.at(path="/public", file) //line 218
GET           /                                                       controllers.Assets.at(path="/public", file="index.html") //line 6
GET           /companies                                              controllers.Assets.at(path="/public", file="index.html")
GET           /login                                                  controllers.Assets.at(path="/public", file="login.html") //line 18

I showed lines what give warns.

I spend a lot of time on trying to repair it I have solved before lot of other problems with good result but with his I surrender.

I will be very thankful for every help.


Solution

  • The reason for error messages is clear that in your code you are calling Assets.at method with two parameters. However signature of Assets.at is;

    public static Action<AnyContent> at(String path, 
                                        String file, 
                                        boolean aggressiveCaching)
    

    which requires three parameters. So you need to provide a boolean value as the third argument to your call in order to get rid of the error messages.

    On the other hand i am wondering the purpose of AssetsController class. You don't seem to use it in your routes.

    About the warning messages; My suggestion would be to replace GET /*file rule with something more specific. Since this rule will match all requests, so any rules declared after this one will not be matched. Then at the end of your routes file declare GET /*file rule to point to return 404 responses.