Unable to resolve reverse routing methods in IntelliJ

前端 未结 7 992
粉色の甜心
粉色の甜心 2020-12-14 10:10

I\'m following one of the play framework tutorials, but I\'m getting compile errors whenever I try to use reverse routing. Firstly,

public static Result java         


        
相关标签:
7条回答
  • 2020-12-14 10:27

    This question was asked a year ago, but to answer for future queries by other coders, the problem is easily solved by adding a "play.Routes" path like this

    public static Result javascriptRoutes() {
        response().setContentType("text/javascript");
        return ok(
                play.Routes.javascriptRouter("jsRoutes",
    
                        // Routes for Projects
                        controllers.routes.javascript.Projects.add(),
                        controllers.routes.javascript.Projects.delete(),
                        controllers.routes.javascript.Projects.rename(),
                        controllers.routes.javascript.Projects.addGroup()
                )
        );
    

    }

    Ensure that you have the proper imports to the class:

    import play.mvc.*;
    import play.data.*;
    
    0 讨论(0)
  • 2020-12-14 10:31

    For people using Play 2.4.x or above, it seems that Play no longer produces reverse routing files for javascript in src_managed et al.

    Instead, you need to include scala-2.xx/routes/main directory as Sources.

    0 讨论(0)
  • 2020-12-14 10:43

    I was running into the same problem and found the solution here: https://github.com/playframework/Play20/issues/969

    In short:

    • Create the directories javascript and ref under the controllers package
    • Run activator compile and now Intellij should get it // used to be 'play compile'
    • If you still got the errors try to run activator idea again // used to be 'play compile'*
    0 讨论(0)
  • 2020-12-14 10:47

    I am using Idea 14.1.4 community edition, i managed to remove the index and route not resolved errors by right clicking on the target folder and marking it as not excluded. NB i run my project using the command line i can not find any run configuration in the ide.

    0 讨论(0)
  • 2020-12-14 10:50

    Pulled from a link provided by @Markus Kittig. Great temporary fix. https://github.com/playframework/playframework/issues/1784#issuecomment-26345523

    Synopsis: Add target/scala-XXX as a managed source and remove the app controllers and views sources flag inside File->Project Structure->Modules->Sources. Then recompile.

    Works on IntelliJ Ultimate 12.1.{4|6}. Created the play application with the command line interface and generated a project file using play idea. Used Play 2.2.0.

    0 讨论(0)
  • 2020-12-14 10:52

    With IntelliJ 14.1 and Play 2.3.8 nothing of the above worked, but the advice from this mailing list worked. (Almost) blatantly copied:

    Locate the target/scala-2.11/src_managed and target/scala-2.11/twirl directories in the project view, then right click and Mark Directory As -> Generated Sources (Root).

    I bumped the scala version and obviously in newer versions of IntelliJ the Root word has been added. Also, you cannot select this from the Project Structure window, the option is not available. It is possible only through the Project pane in the main window. If it refuses to be marked as Generated Sources, try to unmark thetarget directory (Mark Directory As -> Unmark ).

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