Play 2.0 beta - Eclipse configuration

3,232 views
Skip to first unread message

jbtbnl

unread,
Nov 16, 2011, 11:59:27 AM11/16/11
to play-fr...@googlegroups.com
In this post I'll explain how I managed to setup Eclipse for a Play 2.0 beta application.
Guillaume Bort has already announced eclipsify/netbeansify/idealize support to be the next thing on his todo list.
So fortunately we will be saved from this manual configuration in the near future.

I expect that you have a working Play 2.0 installation to start with.
Note that the file locations starting with "application" are relative to your Play 2.0 application.
Locations starting with "play" are relative to your Play 2.0 installation.

Step 1 - new application and sbteclipse

Execute play new application and follow the instructions.
I will be configuring a Java application so I choose option 2.

Now open the file "application\projectplugins.sbt" and add the following lines to the bottom:


resolvers += Classpaths.typesafeResolver
 
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "1.4.0")
 
According to the sbteclipse documentation it is necessary to include the two blank lines. I didn't test whether that's true or not, just included them.

Now cd application and run play to enter the Play 2.0 shell.
Type run to start the application and check localhost:9000 in your browser to check if it is working fine. Stop the server with Ctrl + D.

Step 2 - generate eclipse project and import it

We are in the play shell and execute the eclipse command to generate the eclipse project files. Ok, that was easy!
Now import the eclipse project into eclipse (File -> Import... -> Existing Projects into Workspace) select the application folder and finish.
When you explore the project you will notice Eclipse complaining about a couple of things that can't be found or built.

Step 3 - fix eclipse project setup

There are some settings that need to be modified in Project -> Properties -> Java Build Path.

First go to the tab-sheet Source, there is a duplicate entry for app, so we remove it. However when we remove one and click OK, the other will disappear too!!
So we have to add the "app" folder to Source again.

Now go to the tab-sheet Libraries and Add External JAR "play\repository\local\org.scala-lang\scala-library\2.9.1\jars\scala-library.jar".
We will also Add Class Folder "target\scala-2.9.1\classes" and "target\scala-2.9.1\classes_managed".
The last thing we do is go to the library "play_2.9.1.jar" in the library list, fold it open and click on source attachment and select the folder "play/framework/play/src/main/java".

Now you should have a minimal Play 2.0 application setup in Eclipse, have fun!

Thyx

unread,
Nov 16, 2011, 1:11:12 PM11/16/11
to play-framework
thanks for sharing this !
very usefull.

On Nov 16, 5:59 pm, jbtbnl <jantenbok...@gmail.com> wrote:
> In this post I'll explain how I managed to setup Eclipse for a Play 2.0
> beta application.
> Guillaume Bort has already announced eclipsify/netbeansify/idealize support
> to be the next thing on his todo list.
> So fortunately we will be saved from this manual configuration in the near
> future.
>
> I expect that you have a working Play 2.0 installation to start with.
> Note that the file locations starting with "application" are relative to
> your Play 2.0 application.
> Locations starting with "play" are relative to your Play 2.0 installation.
>
> *Step 1 - new application and sbteclipse*
> *
> *
> Execute play new application and follow the instructions.
> I will be configuring a Java application so I choose option 2.
>
> Now open the file "application\projectplugins.sbt" and add the following
> lines to the bottom:
>
> > resolvers += Classpaths.typesafeResolver
>
> addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "1.4.0")
>
> According to the sbteclipse documentation it is necessary to include the
> two blank lines. I didn't test whether that's true or not, just included
> them.
>
> Now cd application and run play to enter the Play 2.0 shell.
> Type run to start the application and check localhost:9000 in your browser
> to check if it is working fine. Stop the server with Ctrl + D.
>
> *Step 2 - generate eclipse project and import it*
> *
> *
> We are in the play shell and execute the eclipse command to generate the
> eclipse project files. Ok, that was easy!
> Now import the eclipse project into eclipse (File -> Import... -> Existing
> Projects into Workspace) select the application folder and finish.
> When you explore the project you will notice Eclipse complaining about a
> couple of things that can't be found or built.
>
> *Step 3 - fix eclipse project setup*
> *
> *
> There are some settings that need to be modified in Project -> Properties
> -> Java Build Path.
>
> First go to the tab-sheet Source, there is a duplicate entry for app, so we
> remove it. However when we remove one and click OK, the other will
> disappear too!!
> So we have to add the "app" folder to Source again.
>
> Now go to the tab-sheet Libraries and Add External JAR
> "play\repository\local\org.scala-lang\scala-library\2.9.1\jars\scala-librar y.jar".

Xuefeng Wu

unread,
Nov 17, 2011, 12:51:15 AM11/17/11
to play-fr...@googlegroups.com
Thanks and add the "target\scala-2.9.1\src_managed\main" folder to Source will let the scala code call generated template.

hyder

unread,
Nov 17, 2011, 7:07:38 AM11/17/11
to play-fr...@googlegroups.com
Thanks it worked perfectly.

A couple of suggestions:

1) If Eclipse is your IDE of choice, you can add the 2 lines for sbteclipse in play-2.0-beta/framework/resources/scala-skel/project/plugins.sbt and play-2.0-beta/framework/resources/scala-skel/project/plugins.sbt. This will avoid having to do this step every time.

2) The 2 blank lines are not needed.

3)  At the step where you need to add the External scala-library.jar to the build path, you can do this more easily (assuming you have installed the Eclipse Scala plugin):

    a. Right click on project
    b. Scala > Add Scala Library to build path 

Going to play now :)

Cheers,
Ali

sas

unread,
Nov 17, 2011, 8:23:49 AM11/17/11
to play-framework
has anybody figured out how to configure eclipse to run, test and
debug the project?

Chris Bai

unread,
Nov 17, 2011, 8:26:49 PM11/17/11
to play-fr...@googlegroups.com
I am stuck at step 2 - "We are in the play shell and execute the eclipse command to generate the eclipse project files. Ok, that was easy!".

Anyone can share the command to generate the eclipse project files?


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


Xuefeng Wu

unread,
Nov 17, 2011, 10:20:41 PM11/17/11
to play-fr...@googlegroups.com
change your command current directory in you application, and then execute "play", it will take you in sbt command console where you can input "eclipse"

Remco Bos

unread,
Nov 22, 2011, 4:32:41 AM11/22/11
to play-fr...@googlegroups.com
This works great!

The only thing that's missing is the Play 2.0 Scala sources. I have build Play2.0 from Github, in Eclipse I can't attach the scala source folder.. Any ideas?

Pascal Voitot Dev

unread,
Nov 22, 2011, 4:55:27 AM11/22/11
to play-fr...@googlegroups.com
look at sbt-eclipse plugin doc, it's explained...
After adding sbteclipse plugin in project/plugins.sbt, go to play/scala console and type :

eclipse with-sources

It will use the sources to generate the .project

Anyway, after that, you still need to update the build classpath in Eclipse as it doesn't include src_managed containing generated scala view classes...

Pascal

Remco Bos

unread,
Nov 23, 2011, 4:34:57 AM11/23/11
to play-fr...@googlegroups.com
Yes I understand.

But when I build Play2.0 from source and publish-local the artifacts, no source jars are generated.. I'm new to SBT so maybe I have to study it some more..

Hendrik Schnepel

unread,
Nov 25, 2011, 4:45:39 AM11/25/11
to play-fr...@googlegroups.com
Thanks everyone, this thread helped a lot!

However, with Eclipse Indigo, Scala 2.9.1, changes to my templates are not detected without a manual rebuild - not very play'ish. Is this a known behaviour in the beta, or am I missing something?

Regards,
Hendrik

jbtbnl

unread,
Nov 25, 2011, 6:49:13 AM11/25/11
to play-fr...@googlegroups.com
The thing is that play 2.0 detects changes by eclipse, but not the other way around.
For example when you add a scala template, eclipse doesn't notice the compiled class that is created by play 2.0 until you refresh the project.

However, there's a setting for that!
Window -> Preferences -> General -> Workspace
And then check the box "Refresh using native hooks or polling".

Hendrik Schnepel

unread,
Nov 25, 2011, 8:17:55 AM11/25/11
to play-fr...@googlegroups.com
Okay, that setting should help with Eclipse detecting the created classes, but it seems that Play doesn't even create/update, at least not without me accessing the page in the browser.

Detecting file changes with play ~ compile works on actual source files like Controller.scala, but nothing happens when I change a view template. (This is on Windows 7 if that matters.)

??? :-(

jbtbnl

unread,
Nov 25, 2011, 8:28:24 AM11/25/11
to play-fr...@googlegroups.com
Yes, noticed that, it's a play 2.0 thing, play 1.x does instantly detect file changes.
You might want to create a new topic for this to separate topics.

Julien Richard-Foy

unread,
Nov 25, 2011, 11:58:17 AM11/25/11
to play-fr...@googlegroups.com
FYI, with sbteclipse 1.5.0 the build path is correctly set (app is not
duplicated and src_managed is included) ^^

sveri

unread,
Dec 21, 2011, 6:35:37 AM12/21/11
to play-framework
Thanks for the little tutorial, it worked fine for me.
However, now, when i open the Application controller, i get an error
which says:
"index cannot be resolved" from:
return ok(index.render("Your new application is ready."));

I wonder if there is a fix for that. The application itself works
fine, i think it's just eclipse related.
I am using Windows 7 with jdk7.

Greetings
Sven

On 16 Nov., 17:59, jbtbnl <jantenbok...@gmail.com> wrote:
> In this post I'll explain how I managed to setup Eclipse for a Play 2.0
> beta application.
> Guillaume Bort has already announced eclipsify/netbeansify/idealize support
> to be the next thing on his todo list.
> So fortunately we will be saved from this manual configuration in the near
> future.
>
> I expect that you have a working Play 2.0 installation to start with.
> Note that the file locations starting with "application" are relative to
> your Play 2.0 application.
> Locations starting with "play" are relative to your Play 2.0 installation.
>
> *Step 1 - new application and sbteclipse*
> *
> *
> Execute play new application and follow the instructions.
> I will be configuring a Java application so I choose option 2.
>
> Now open the file "application\projectplugins.sbt" and add the following
> lines to the bottom:
>
> > resolvers += Classpaths.typesafeResolver
>
> addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "1.4.0")
>
> According to the sbteclipse documentation it is necessary to include the
> two blank lines. I didn't test whether that's true or not, just included
> them.
>
> Now cd application and run play to enter the Play 2.0 shell.
> Type run to start the application and check localhost:9000 in your browser
> to check if it is working fine. Stop the server with Ctrl + D.
>
> *Step 2 - generate eclipse project and import it*
> *
> *
> We are in the play shell and execute the eclipse command to generate the
> eclipse project files. Ok, that was easy!
> Now import the eclipse project into eclipse (File -> Import... -> Existing
> Projects into Workspace) select the application folder and finish.
> When you explore the project you will notice Eclipse complaining about a
> couple of things that can't be found or built.
>
> *Step 3 - fix eclipse project setup*
> *
> *

Guillaume Bort

unread,
Dec 21, 2011, 8:18:41 AM12/21/11
to play-fr...@googlegroups.com
You have to add the target/scala-2.9.1/classes_managed directory to
your build path in eclipse. It contains classes for generated stuff
like templates and routes.

It will just work out of the box with the final 'eclipse' command that
will be available in Play 2.0 final.

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>

--
Guillaume Bort

Reply all
Reply to author
Forward
0 new messages