play2 framework my template is not seen. : package views.html does not exist

11,217

Solution 1

Omg, the problem was so easy! *classes_managed* (this folder keeps compiled scala templates) were not updated with newly added templates. I did try to call play compile yesterday, it doesn't help. New templates from new package were not compiled. This morning I've called play clean compile aaand... hooray! I did get compiled templates and problem with missing package gone away (don't forget to refresh Eclipse project, force it to update exisitng project structure from file system. It likes to cache everything.)

Sorry for disturbing, seems like I wasn't attentive while reading documentation :(

Solution 2

The problem is that Eclipse isn't seeing the src_managed folder, which is dynamically updated by the play framework.

Go to project → properties → java build path → libraries (it's a tab) → add external class folder

Then select the src_managed folder, which should be in the folder target->scala-x.x.x in the same directory as your project.

This will add src_managed to your build path, and Eclipse will now understand that these templates are valid.

You may need to run 'play clean compile' in the play framework console You may then need to run project -> clean in eclipse

Solution 3

In Play 2.5, I was able to fix this issue with:

import the view:

import views.html.index;

Then inside the controller:

return ok(index.render("Hello"));

Something like this without complex problems, strange that using it like return ok(views.html.index.render("Hello"))) was not working while importing then use it worked well.

Sure all answers here helpful as well, sometimes the issue simply is to clean and then compile, but even this not really solving issue all the time, regardless the IDE you are using, I was using CLI and was giving cannot find symbol error as well.

Solution 4

To resolve "package views.html doesn not exist" :

Run "sbt compile" or "sbt clean compile". That should create a folder structure in your project as target\scala xx\twirl\main\views.html

Share:
11,217
Capacytron
Author by

Capacytron

Updated on June 04, 2022

Comments

  • Capacytron
    Capacytron almost 2 years

    The problem is that controller doesn't see template I want to use:

    [etl_admin] $ compile [info] Compiling 3 Scala sources and 4 Java sources to D:\ECLIPSE_WORKSPACES\play2_apps\etl_admin\target\scala-2.9.1\classes... [error] D:\ECLIPSE_WORKSPACES\play2_apps\etl_admin\app\controllers\EtlWorkflowSeqNodeController.java:7: error: package views.html.etlworkflowseqnode does not exist [error] import views.html.etlworkflowseqnode.list; [error]
    ^ [error] D:\ECLIPSE_WORKSPACES\play2_apps\etl_admin\app\controllers\EtlWorkflowSeqNodeController.java:14: error: cannot find symbol

    [error] list.render(EtlWorkflowSeqNode.findTree(jobId)) [error] ^ [error] symbol: variable list [error]
    location: class EtlWorkflowSeqNodeController [error] 2 errors [error] {file:/D:/ECLIPSE_WORKSPACES/play2_apps/etl_admin/}etl_admin/compile:compile: javac returned nonzero exit code [error] Total time: 7 s, completed 05.06.2012 17:14:44

    Here is controller code:

    package controllers;
    
    import play.mvc.Controller;
    import play.mvc.Result;
    import models.EtlWorkflowSeqNode;
    import play.db.jpa.Transactional;
    import views.html.etlworkflowseqnode.list; /*LINE #7, Eclipse really tells that there is no such package*/
    
    public class EtlWorkflowSeqNodeController  extends Controller {
    
        @Transactional
        public static Result list(Integer jobId) {
            return ok(
                list.render(EtlWorkflowSeqNode.findTree(jobId))
            );
        }
    }
    

    I've attached an image with my project tree. There is such package and there is template named "list". My Eclipse what do I do Wrong

  • Bachi
    Bachi almost 12 years
    I have possibly related problem: When I change a scala template, e.g. add another required parameter to it which is not yet added in the controller, I would expect to get an error in Eclipse. Hoewever, Eclipse seems somehow not to update the changes in the scala template? When I open the page in the browser, I get the expected compilation error msg. Any ideas how to overcome this?
  • paradigmatic
    paradigmatic almost 12 years
    @Bachi You should ask a new question.
  • Capacytron
    Capacytron almost 12 years
    1. Run play console, 2. execute clean then execute compile, 3. go back to Eclipse and refresh your project. Eclipse we'll see changes to templates (refresh compiled bytecode from managed_classes folder) and you can continue to use it.
  • Bachi
    Bachi almost 12 years
    Sergey: Thanks, this solves it indeed. But I am still wondering if this is the 'official workflow' when changing scala templates... @paradigmatic You're right, but this seemed to closely related to this quetion..
  • paradigmatic
    paradigmatic almost 12 years
    @Bachi Yes I know. But you have to think about other users who may have the same problem than you. It'is easier to find information in questions/answers than in comments
  • Cam
    Cam over 9 years
    (Update) with activator the sequence of commands to resolve this issue is: $ activator [project-name] $ clean [project-name] $ compile
  • Anton Kuzmin
    Anton Kuzmin over 9 years
    It seems that nowadays the templates are not at src_managed but at twirl directory.
  • mkurz
    mkurz over 7 years
    No workarounds are needed anymore: Just upgrade sbteclipse to version 5.1.0 (which was released on January 12th 2017) - it fixes this bug.
  • daniyel
    daniyel about 7 years
    did not work for me. I do not see any folder in target/scala-2.10 named twirl
  • trupti rath
    trupti rath almost 7 years
    I use to run "sbt clean compile" from my intellij terminal and it works for me every time. If that does not work for you try cleaning up your system cache by choosing File | Invalidate Caches/Restart from Intellij menu
  • Rajat
    Rajat over 5 years
    in Intellij Idea sbt shell you have to run clean and then compile separately