Getting and Building Sling
A quick guide for getting the Sling source, then building and running the resulting Sling instance; either without or with Eclipse.
Sling can easily be built:
- from the command line (using SVN and the Maven command line tool)
- or using Eclipse
Note that you don't have to build Sling yourself, if you don't need the bleeding-edge stuff you can get prebuilt binaries from the Downloads page.
Prerequisites
Before you begin, you need to have the following tools installed on your system:
- Java 5 or higher; Java 6 recommended
- Maven 2.2.1 or later; enforced by the Sling parent pom
If you want to set up Eclipse (not required to build Sling) you'll also need the following installed:
- Eclipse (tested with 3.4.2 and 3.5.x on Win XP, SP3); just a plain installation of the platform runtime binary and the JDT will be adequate (you can install the IDE for Java Developers for convenience)
- M2Eclipse plugin for Eclipse (sonatype) -> instructions
- Subversive plugin or Subclipse-plugin for Eclipse
Environment Setup
The full build process requires quite a lot of resources, so you may run into limits. The following hints should show you what to setup before building Sling.
Java Heap Space
- Problem - Build aborts with reports of java.lang.OutOfMemoryError: Java heap space. Alternatively the build may randomly fail during the integration tests.
- Platforms - This happens on all platforms
- Fix - Increase the values of the maximum heap and perm space for the build by setting or extending the MAVEN_OPTS environment variable.
For 32bit platforms you should use
For 64bit platforms, you should use
For more information see SLING-443 and SLING-1782.
Environment Variable Space
- Problem - Build aborts when trying to launch the integration tests with the message
This problem is caused by insufficient swap space. When running the integration tests in the launchpad/testing modules, a process is launched by calling the exec system call. This copies the process (copy-on-write, though) and thus allocates as much virtual memory as is owned by the parent process. This may fail if swap space is exhausted.
- Platform - OpenSolaris
- Fix - If this issue persists you will need to check your system requirements and configuration with regard to swap, before taking action - if necessary.
Configuring Maven
See MavenTipsAndTricks.
Getting the Sling Source
With SVN
- Checkout Sling from the Repository.
With Eclipse Subversive or Subclipse
First note how simple the above SVN instructions are...but if you really want to do this, read on.
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/.
Also, make 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 it's time to adjust some configs
- Turn off automatic build (Menu: Project->Build Automatically)
- Go to menu: Eclipse->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
Checkout 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/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 laptop)!
Possibly something in sling-builder might get a bit messed up (I didn't experience that problem, but Pontus reported it) 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
Building Sling
With the Maven command line tool
- Enter the directory, then do a full build and local install (below are unix/linux commands, slightly different under windows)
Note: On windows just leave out /dev/null and make sure you have an empty settings.xml file for maven (located in your user directory under .m2).
- Enter the launchpad/builder directory and launch Sling for the first time
Messages should now be printed to the console which is being used as the "log file"; the -f command line option is set to -, indicating the use of standard output as the log file. The -c sling command line option instructs Sling to use the sling directory in the current directory for its data store, which is the Apache Felix bundle archive, the Jackrabbit repository data and configuration. You may also specify another directory here, either a relative or absolute path name (See also Configuration for more information).
Use the -h option to see the list of flags and options.
After all messages have been printed you should be able to open the Sling Management Console by pointing your web browser at http://localhost:8080/system/console. You will be prompted for a user name and password. Enter admin for both the user name and the password (this may be set on the Configuration page later). From this console, you can manage the installed bundles, modify configuration objects, dump a configuration status and see some system information.
To stop Sling, just hit Ctrl-C in the console or click the Stop button on the System Information page of the Sling Management Console.
With M2Eclipse
- 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
Alternative setup in Eclipse without M2Eclipse plugin
In the case that you do not want to use the M2Eclipse plugin there's another setup that lets you have the automatic build turned on:
- Checkout the whole sling trunk (with subversive or the subclipse plugin) from SVN to a single project
- Then manually add all src/main/java and src/test/java of the bundles to the project as source folders
- Add all required libraries to the build path
- 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 will probably get OutOfmemory errors.
Congratulations ! You should now have a running Sling instance, that you can start playing around with.
Further Tips and Tricks
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
- Open Menu Run-> Debug configurations
- Right-click on "Remote Java Applications"
- Choose "New"
- In the "Connect" tab choose the Eclipse Sling Project for the field "Project" with the browse button
- Let the Connection type be "Standard (Socket Attach)"
- The host should be localhost
- Set the Port to 30303
- On the source tab click the "Add" button
- Select "Java Project"
- Select all Sling projects and click OK
- Click "Debug"
Now you should be able to set breakpoints, evaluate properties, and so on as usual.
Debug Maven Tests in Eclipse
In the same way as you can debug the sling app, you are also able to debug a maven test. Just run the maven tests like this
The tests will automatically pause and await a remote debugger on port 5005. You can then attach to the running tests using Eclipse. You can setup a "Remote Java Application" launch configuration via the menu command "Run" > "Open Debug Dialog..." (see above).
For more information on this see the Maven Surefire Docu.
Simple way to develop new bundle in Eclipse 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 from the command line with "mvn -P autoInstallBundle clean install -Dsling.url="" href="http://localhost:8080/system/console" class="external-link" rel="nofollow">http://localhost:8080/system/console"
If adding dependencies to the poms, run mvn eclipse:eclipse again and refresh the project in Eclipse. Debugging works as described above.