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.
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: http://community.polarion.com/projects/subversive/download/integrations/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:
- Menu: File->Switch Workspace->Other...
- Enter a path for the new workspace and click OK
- When Eclipse has restarted its time to adjust some configs
- Turn off automatic build (Menu: Project->Build Automatically)
- Go to menu: Window->Preferences, in the preferences dialog select Java -> Compiler -> Errors/Warnings
- Expand the "Deprecated and restricted API" and change "Forbidden references (access rules)" from "Error" to "Warning"
- Click OK
Get the Sling source
- Menu: File->Import
- In the Import wizard select Maven->"Check out Maven Projects from SCM"
- Click next
- In the "SCM URL" field pick "SVN" and enter the url "http://svn.apache.org/repos/asf/incubator/sling/trunk"
- 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:
- In the Project Explorer right click on the "sling-builder" project and select the Team->Revert... menu
- A couple of changes will be displayed
- Click OK
- Make sure you're in the Java perspective (Menu: Window->Open Perspective)
- Menu: Run->Run Configurations...
- In the Run Configurationa dialog right click on "Maven Build" and select "New"
- Change Name to "Build Sling"
- Click "Browse Workspace..." and select "sling-builder"
- Enter "clean install" in Goals
- Click on the JRE tab
- Enter "-Xmx256m -XX:MaxPermSize=128m" in "VM arguments"
- Click Apply
- 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
- 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 org.apache.sling.launchpad.app-4-incubator-SNAPSHOT.jar"
- Open Menu Run-> Debug configurations
- Right click on "Remote Java Applications"
- Choose "New"
- in the "Connect" tab enter org.apache.sling.launchpad.app in the field "Project"
- Let the Connection type be "Standard (Socket Attach)"
- the host should be localhost
- set the Port to 30303
- On the source tab click on the "Add" button
- Select "Java Project"
- Select all Sling projects and click OK
- Click "Debug"
No you should be able to set breakpoints, evaluate properties, and so on as usual.