Spark source code in IntelliJ IDE

This is a short tutorial on how to load the Spark source code in the IntelliJ IDE.

IntelliJ is very versatile, and offers many options that are not explored in this guide. Instead, this guide focuses on the bare minimum that is needed to get started.

Prepare your environment

This guide assumes that you have IntelliJ installed, and have a copy of the source code available locally. Additionally, a Java Development Kit (version 8) should be installed.

Start by creating a new, empty workspace.

Create a project and import the source code

The Spark source code is using an Apache Maven project structure. As IntelliJ recognizes this structure, importing the source code into an IntelliJ project is very easy.

Select the 'import' option. This will quickly import the Spark source code into a new IntelliJ project.

Use the 'import' functionality of IntelliJ. Select the option that will import our (pre)existing Maven project. IntelliJ project options. Defaults should be ok
Creating a new project in IntelliJ.

Using the 'import' option, select the directory in which the Spark source code is stored. Select the Maven project file (pom.xml).

IntelliJ will automatically recognize and process the Maven structure of Spark, as soon as it is pointed to the correct directory. In most cases, You can accept the defaults on the following screens of the import wizard.

Project to import. Select the SDK to use. This should auto detect your JDK and path IntelliJ Project Name and Path. Defaults should be ok.
Use the 'import' functionality of IntelliJ to import the source code.

Once the import wizard has been closed, the IntelliJ workspace will show. There are menu bars to the left and right edge. Left edge, click "Project" to extend Project tree. On the right, click "Maven Project" to extend Modules. That's it! You're ready to start working on the code now!

IntelliJ workspace. IntelliJ workspace.
Spark modules in the IntelliJ workspace

Run Spark from IntelliJ

When developing, it is often useful to run the code straight from your IDE. The following will explain how you can start a Spark instance from the code that is in the IntelliJ workspace.

Launch the 'Startup' class as a Java application. The Spark login screen, after launching the 'Startup' class.
Run Spark straight from the source code.

The 'spark-core' module contains a class named Startup (in the org.jivesoftware.launcher package) that can be used to start Spark. Find the class in the Project Explorer, and open its context menu (right-click on the file). In that menu, use the 'Run Startup.main()' option. IntelliJ wil start to build Spark from the source code, after which Spark itself is started. If everything goes well, you will see the Spark login screen within a matter of seconds!