Getting and Building Sling
A quick guide for getting the Sling source, setting up Eclipse, and running the resulting Sling instance.
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 should have installed the following tools on your system:
- Java 5 or higher, Java 6 recommended
- Maven 2.0.7 (or later), Maven 2.1.0 recommended
To set up Eclipse you'll also need:
Environment Setup
The full build process requires quite some 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 report of java.lang.OutOfMemoryError: Java heap space. This mostly happens while building the Jackrabbit Server module jcr/jackrabbit-server.
- Platforms - Windows XP, Mac OSX, OpenSolaris
- Fix - Set the a higher value for the maximum heap and perm space for the build by setting or extending the MAVEN_OPTS environment variable:
Environment Variable Space
- Problem - Build aborts when trying to launch the integration tests with message
- Platform - OpenSolaris
- Fix - This problem is caused by missing 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.
Configuring Maven
See also MavenTipsAndTricks.
Many of the Sling modules have been released into the Apache Incubator Maven 2
repository. This repository is not visible by default to Maven 2. To enable its use, it is easiest if you configure it into your local maven settings found in $HOME/.m2/settings.xml by default:
<?xml version="1.0"?>
<settings>
<profiles>
<profile>
<id>apache-incubation</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>apache.incubating</id>
<name>Apache Incubating Repository</name>
<url>http://people.apache.org/repo/m2-incubating-repository</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>apache.incubating.plugins</id>
<name>Apache Incubating Plugin Repository</name>
<url>http://people.apache.org/repo/m2-incubating-repository</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
Getting the Sling Source
With SVN
- Checkout Sling from the Repository.
With Eclipse Subversive or Subclipse
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 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
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 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
Build Sling
With the Maven command line tool
- Enter the directory and do a full build and local install (below are unix/linux commands, slightly different under windows)
- Enter the launchpad/app directory and launch Sling for the first time
Messages should now be printed to the console which is used as the "log file" because the -f command line option is set to - indicating to use 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).
After all messages have been printed you should now 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 as both the user name and the password (this may be set on Configuration page later). From this console, you may manage the installed bundles, modify configuration objects, dump a configuration status and get some system information.
To stop Sling, just hit Ctrl-C at 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 case you do not want to use the M2Eclipse plugin there's another setup which lets you have turned on the automatic build:
- Checkout the whole sling trunk with subversive or subclipse plugin from the 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 probably get OutOfmemory errors.
Congratulations ! You should now have a running Sling instance, which you may 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
"java -Xmx384M -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=30303,server=y,suspend=n -jar org.apache.sling.launchpad.app-5-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"
Now you should be able to set breakpoints, evaluate properties, and so on as usual.
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 on the command line with "mvn -P autoInstallBundle clean install -Dsling.url="" class="nobr">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.