Child pages
  • Setting up Eclipse 3.4 for Sling
Skip to end of metadata
Go to start of metadata

To setup the Eclipse IDE to work with the Sling project properly seems to be not very straightforward at a first look, but be calm, it's not rocket science to do. This little manual should help you to setup Eclipse for Sling fast.


  • Installed Eclipse Ganymede (tested with 3.4.2 on Win XP, SP3)
  • Installed Maven2 (tested with 2.1.0)
  • Installed M2Eclipse plugin for Eclipse (sonytype) -> instructions
  • Installed Subversive plugin or Subclipse-plugin for Eclipse
  • Java 5 or higher (Java 6 recommended)

If you use the Subversive plugin make sure you have installed the "Subversive Integration for M2Eclipse Project" which can be found under the following Eclipse update site:

Make also sure, that you have installed either the "Maven SCM handler for Subclipse" or the "Maven SCM handler for Subversive"

Create a new workspace

It's best to create a new workspace for the sling project:

  1. Menu: File->Switch Workspace->Other...
  2. Enter a path for the new workspace and click OK
  3. When Eclipse has restarted its time to adjust some configs
  4. Turn off automatic build (Menu: Project->Build Automatically)
  5. Go to menu: Window->Preferences, in the preferences dialog select Java -> Compiler -> Errors/Warnings
  6. Expand the "Deprecated and restricted API" and change  "Forbidden references (access rules)" from "Error" to "Warning"
  7. Click OK 

Get the Sling source

  1. Menu: File->Import
  2. In the Import wizard select Maven->"Check out Maven Projects from SCM"
  3. Click next
  4. In the "SCM URL" field pick "SVN" and enter the url ""
  5. Click Finish

Eclipse will now start to download the source and import the Maven projects. You might encounter some "Problem Occured" dialogs about "An internal error..." but just click OK on those and let Eclipse continue with the import. Be warned: This could take some time (it was 30 minutes on my lap)!

Maybe something in sling-builder gets a bit messed up (I didn't ran into that problem, but Pontus reported that) then you can simply fix it with revert:

  1. In the Project Explorer right click on the "sling-builder" project and select the Team->Revert... menu
  2. A couple of changes will be displayed
  3. Click OK

Build Sling

  1. Make sure you're in the Java perspective (Menu: Window->Open Perspective)
  2. Menu: Run->Run Configurations...
  3. In the Run Configurationa dialog right click on "Maven Build" and select "New"
  4. Change Name to "Build Sling"
  5. Click "Browse Workspace..." and select "sling-builder"
  6. Enter "clean install" in Goals
  7. Click on the JRE tab
  8. Enter "-Xmx256m -XX:MaxPermSize=128m" in "VM arguments"
  9. Click Apply
  10. Click Run

This should build Sling.

Debug Sling in Eclipse

You can use remote debugging to debug Sling in Eclipse, here's a little How-To:

  1. start Sling from the command line with
    "java -Xmx384M -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=30303,server=y,suspend=n -jar"
  2. Open Menu Run-> Debug configurations
  3. Right click on "Remote Java Applications"
  4. Choose "New"
  5. in the "Connect" tab enter in the field "Project"
  6. Let the Connection type be "Standard (Socket Attach)"
  7. the host should be localhost
  8. set the Port to 30303
  9. On the source tab click on the "Add" button
  10. Select "Java Project"
  11. Select all Sling projects and click OK
  12. Click "Debug"

Now you should be able to set breakpoints, evaluate properties, and so on, as usual.

Alternative setup in Eclipse without M2Eclipse plugin

In case you do not want to use the M2Eclipse plugin there's another setup which lets you have turned on the automatic build:

  1. Checkout the whole sling trunk with subversive or subclipse plugin from the SVN to a single project
  2. Then manually add all src/main/java and src/test/java of the bundles to the project as source folders
  3. Add all required libraries to the build path
  4. Now you can build either in Eclipse or even better use "mvn clean install" on the command line

If you use "mvn clean install" to build Sling be sure you have set MAVEN_OPTS to "-Xmx384m -XX:PermSize=256m" otherwise you probably get OutOfmemory errors.
Debugging works as described above. I can really recommend the alternative setup if you do not want to struggle with the IDE too hard and it's not too upsetting to have a console open beside Eclipse.

Simple way to develop new bundle for Sling

The easiest way that I found is to create a new folder in the existing Eclipse workspace. After that you can follow these steps:

  • Start by copying and adapting an existing Sling pom.xml (eg. the pom.xml from the espblog sample)
  • Generate the Eclipse project files using mvn eclipse:eclipse
  • Choose File/Import in Eclipse and select "Existing projects into workspace"
  • Now you can create, edit and compile the files in Eclipse
  • To create the bundle jar and install it, just use the command line "mvn clean install" in the project directory
  • If you have a running Sling app you can install the bundle on the command line with "mvn -P autoInstallBundle clean install -Dsling.url=http://localhost:8080/system/console"

If adding dependencies to the poms, run mvn eclipse:eclipse again and refresh the project in Eclipse. Debugging works als described above.

  • No labels

1 Comment

  1. Anonymous

    I am on Mac OS X. I am the only to not be able to select a SCM URL Type in the maven import dialog?