Matthew Steven Monkan
Matthew Steven Monkan

Reputation: 9130

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

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?

Upvotes: 15

Views: 22686

Answers (7)

mesompi
mesompi

Reputation: 699

In my case I just added the following import:

import views.html.*;

The Eclipse IDE removes the mentioned line if you organize your imports through CTRL + SHIFT + O

Upvotes: 0

Matthias Braun
Matthias Braun

Reputation: 34343

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.

Upvotes: 2

jakob
jakob

Reputation: 5995

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!

Upvotes: 4

yoda
yoda

Reputation: 173

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

Upvotes: 1

estmatic
estmatic

Reputation: 3449

I do the same play compile that InPursuit suggested, but when adding a completely new view I've found that I need to close the project and reopen it so that eclipse rebuilds its "content assist" information.

I just right-click the project and choose "Close Project", and then right-click the now empty project folder and choose "Open Project". It's annoying but that's the only way (short of restarting eclipse) that has worked for me. Sometimes the red squigglies are still there after reopening but they go away if I do a refresh.

Upvotes: 0

kompot
kompot

Reputation: 798

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).

Upvotes: 3

InPursuit
InPursuit

Reputation: 3293

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)

Upvotes: 25

Related Questions