目次

Version 1, last updated by parsa28 at Nov 02 04:28 UTC

Quickstart with Eclipse and Gradle for beginners

If you want to get started really quick and build a robust and dynamic development environment, you can follow these simple steps.

Requirements

  1. Eclipse 3.5.0+ (not sure about previous versions) with Scala plugin
  2. Git

Step 1

Open terminal and clone sample Lift project:


$ git clone http://github.com/jeppenejsum/liftstart.git

Step 2

Open the ‘build.gradle’ file with a text editor and change Scala and Lift versions to your favorite ones:


$ cd liftstart
$ vi build.gradle

Change this two lines for current stable releases:

scalaVersion = '2.8.0'
liftVersion = '2.1'

Step 3

Download all dependencies (including Gradle itself), compile and run Jetty with sample Lift application. (Note: Jetty is embedded into the project, no need to install it separated)


$ ./gradlew jettyRun

Step 4

Check your application up and running on http://localhost:8080/

Step 5

Ok cool, now let’s integrate this with Eclipse:
First go to Eclipse: Preferences > Java > Build Path > Classpath Variables. Add a classpath variable with name: GRADLE_CACHE and path: ~/.gradle/cache (/User/username/.gradle/cache).
Now go back to terminal to the liftstart folder and:


$ ./gradlew eclipse
:eclipseClasspath
:eclipseProject
:eclipseWtp
:eclipse
BUILD SUCCESSFUL

Total time: 11.27 secs

After it’s done, go to Eclipse: File > Import > Existing Projects into Workspace and browse to the ‘liftstart’ folder and open it. You should now have the whole project in your Eclipse workspace.

Step 6

In the Package Explorer (left pane in Eclipse) open liftstart, and browse to src/test/scala/RunWepApp.scala Run it and you will have your Eclipse project built and running along with the embedded Jetty. (You can check the sample app again on http://localhost:8080/ )

Step 7 [Optional]

If you’re looking for even more fun, you can add JRebel to your development environment. JRebel allows you to see your changes as you make them, without restarting. Download it from their website and install it. It’s a commercial software but don’t worry, they generously provide us Scala developers with a free license. (Go to their website and obtain your free license)

After adding JRebel, go to RunWebApp.scala again and open Run > Run configurations. There, in the JRebel tab, select Enable JRebel agent. And Run your project. Now try to change something while the project is running (e.g. browse to src/main/scala/example/snippet/HelloWorld.scala and change d.toString() with some string) and save the file. Now go to your browser and refresh to see the results immediately.

Troubleshooting

*Getting strange errors while building in Eclipse: Make sure your project folder or at least the ‘build’ folder inside it are writable.

  • “Java compiler level does not match the version of the installed Java project facet.” in Eclipse Problems window: Right click on the project, go to Project Facets, change the Java version from 1.4 to your current version (e.g. 6.0 / 1.6)
  • “This project needs to migrate wtp metadata.”: Right click on the error in Problem Window and just delete it, you should be fine

Disclaimer

This tutorial is a mashup of 2 different tutorials by Jeppe Nejsum Madsen on his blog his blog. The liftstart project on GitHub is also generously provided by him so all the credit goes to him.