Newly created scala.html views are not being recognized in Play Framework 2.x

22,103

Solution 1

The views are not compiled by Eclipse but can be seen by eclipse after they're compiled by Play as long as the target\scala-2.9.1\classes_managed directory is in your eclipse project build path.

Try running "play compile" on the command line (or just "compile" if you're already in the play console) and then refreshing your project within eclipse (select the project and hit F5)

Solution 2

For you IntelliJ 12 users out there: I upgraded to Play 2.1 which broke my Play IntelliJ Support plugin. This caused IntelliJ to not recognise:

import views.html.*;

so when hitting cmd + o to optimize my imports it was removed. This resultet in a compilation error when running play clean compile since the views were not imported:

[error] symbol  : variable index
[error] location: class controllers.Application
[error]         return ok(index.render());
[error]                   ^
[error] 1 error
[error] (compile:compile) javac returned nonzero exit code
[error] application -

So I uninstalled the plugin, restarted IntelliJ and viola everything works like a charm!

Solution 3

Your can use

~compile

in play console so that updated templates will get recompiled on file change and probably Eclipse will see changes immediately (IDEA does that).

Solution 4

This happened to me after I copied an entire project and tried to modify it. The changes in the HTML views would just be ignored since they were not compiled.

Doing activator clean compile run fixed the problem.

Solution 5

I have had this behaviour as well. Turns out it was a typical copy/paste problem. I forget to update the import statement.

Share:
22,103
Matthew Steven Monkan
Author by

Matthew Steven Monkan

Veteran software development expert who enjoys mentoring, leading, and solving problems that benefit society.

Updated on October 26, 2020

Comments

  • Matthew Steven Monkan
    Matthew Steven Monkan over 3 years

    I am using Play Framework 2.0.1. I have created a Java application using the "play new" command. By default, two views are created: index.scala.html and main.scala.html

    I've done a few sample tutorial apps that allow me to render those views. However, when I add a new view (by default in app/views/), I get a compilation error that it cannot be found:

    public static Result getAllCars() {
        List<Car> cars = Car.getAllCars();
        return ok(simpleCarView.render(cars));
    }
    

    I can do

    import views.html.index;
    import views.html.main;
    

    but not

    import views.html.simpleCarView; 
    

    Error in console:

    cannot find symbol
    [error] symbol : variable simpleCarView
    [error] location: class controllers.Application
    

    I've tried adding scala.html views in the file directory and from within eclipse, but for some reason they are not found. I've also tried restarting the default Netty server.

    Any ideas on what is causing this?

  • Matthew Steven Monkan
    Matthew Steven Monkan almost 12 years
    I have done "play compile" and I get the error I posted in my question. When I compile, it says two scala sources and 1 Java source is being compiled. I'm assuming it's talking about my Application.java and index.scala.html and main.scala.html. But other views are not compiling under the views folder.
  • Matthew Steven Monkan
    Matthew Steven Monkan almost 12 years
    After doing a lot of refreshing, deleting/readding views, re-compile, etc... the problem seems to have gone away. I've been unable to reproduce the odd behavior I described earlier. In general your answer describes the best steps to go through, so I'll mark it as the answer.
  • stian
    stian over 11 years
    Works well. You can also use ~run to get the templates automatically recompiled on the fly while running the server.
  • matt
    matt over 10 years
    @Matt the key is to comment out the line in your Controller that is giving the compiler error (red underline) before running play compile or you will keep seeing that error. Once you've commented that out and run play compile, you can refresh eclipse, uncomment the line, and import the view to the controller. Hopefully that clarification saves some headaches for people who come across this.
  • matanster
    matanster over 9 years
    This really sucks. My feeling is we don't really need a framework unless it really acts like one...
  • pitchblack408
    pitchblack408 over 8 years
    This doesn't work anymore because the there is no scala-2.4.2 folder in the target folder anymore