How to make Eclipse see the changes in Play! compiled templates?
Asked Answered
F

4

22

So, I'm trying out Play 2 with Eclipse. I create a new project, compile it, run eclipsify and import it into Eclipse. So far so good.

The problem I'm having is that when I make a change in the Scala template, my Java controllers can't see it, and Eclipse marks the code as invalid. For example:

I added a second parameter in my index template

@(message: String, nesto:Integer)

When I try to render my file from the controller, the following line displays an error, because Eclipse still thinks that the index.render takes one String.

return ok(index.render("Your new application is ready.",2));

I turned on the workspace refreshing in Eclipse, and play eclipsify automatically added the classes_managed directory to the build path.

Frosty answered 6/4, 2012 at 11:43 Comment(0)
T
6

I did the following things :

  1. As you did, I turned on the workspace auto-refresh (in settings, General -> Workspace, then select "Refresh using native hooks or pooling")
  2. I removed the classes_managed directory generated by play eclipsify from my build path, and I added it manually using "Add external class folder"

And then it worked for me. It seems that there is a bug with the eclipsify command.

Taka answered 6/4, 2012 at 12:42 Comment(3)
Just edited the answer, since I had used "Add external class folder" instead of "Add class folder"Taka
Still no go. What version of Eclipse you used?Frosty
Upgrade sbteclipse to version 5.1.0 (which was released on January 12th 2017) - it fixes this bug.Debutant
W
5

The trick is to have Play building automatically in the background (template files are not currently built by Eclipse, so you need Play to translate those for you). It's all explained in detail here:

[dead link] http://scala-ide.org/docs/tutorials/play20scalaide20/index.html

[try this one] http://scala-ide.org/docs/tutorials/play/index.html#installing-the-scala-ide-play2-plug-in

Weinrich answered 6/4, 2012 at 18:35 Comment(2)
I am running Play with play ~run, so it is building templates in the background. The stuff on the link you posted is working fine when the controller is written in Scala.Frosty
Sorry, I somehow missed that the controller was in Java.Weinrich
N
4
  1. Run 'play eclipse' on the command line
  2. In Eclipse, refresh your Project via hitting F5
Na answered 9/1, 2014 at 16:41 Comment(1)
Also make sure you upgrade sbteclipse to version 5.1.0 (which was released on January 12th 2017) - it fixes related bugs.Debutant
C
1

For Java Play Framework v2.4.6 (activator v1.3.7) with Eclipse Mars:

Instead of @(message: String, nesto:Integer) , have you tried this @(message: String)(nesto: Integer)?

So that you will not have a "can not resolve error" with your index.render(), you can add this <classpathentry kind="lib" path="target/scala-2.11/classes"/> to your .classpath or right-click on your project -> Build Path -> Configure Build Path -> Add Class Folder and make it point to target/scala-2.11/classes.

Collier answered 8/2, 2016 at 15:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.