As part of switching to Apache Maven for building CloudStack, the .classpath and .project files used by Eclipse were removed. This page describes how to get CloudStack loaded into an Eclipse workspace. For more details on the actual build process with maven see How to build CloudStack. A modern appliance based CloudStack development can be explored with MonkeyBox.
To minimize confusion, start with a clean workspace with no other projects.
Download the CloudStack source code via git with:
This wiki page shows how to install the Maven integration for Eclipse plugin. (For those using Yoxos, just search for M2E and add it to your Eclipse build)
After installing the plugin, restart Eclipse.
Now you can import CloudStack using the M2E plugin:
Eclipse will import the projects and build the code. At this point you should be able to develop and debug code as usual within Eclipse.
CloudStack is a big project and it requires more memory for Eclipse. Here's how to give it more memory.
CloudStack has a lot of projects that are really just for grouping the different type of projects. The problem is in Eclipse, the files that belong in sub-projects also show up in the projects. This causes a lot of problems with the Open Resource dialogue, which is often used to quickly get to a file if you know the filename already. These problems include the multiple copies of the same .class files showing up and multiple copies of the same .java file showing up. If you select the wrong .java file, then a lot of the references doesn't work. Upon further inspection, the reason is because the same .java and .class file is included by both the project and the parent project. To get rid of this problem, do the following. Unfortunately, you have to do this for every parent project.
What this does is to tell Eclipse that the sub-directories under parent projects should not be included in the resource list, thus avoiding the the duplicate resources in the Open Resource dialogue box. If the parent project does have a directory that you want, then you can add that to a include filter. Note that you can not use * as the folders because that would exclude the .settings folder which eclipse uses to keep its metadata and will cause the m2e plugin to have problems.
Here's a list of parent projects you should do this with:
Eclipse by default uses the the Maven pom.xml to tell it where to put its generated files. Unfortunately, that has one big disadvantage. Everytime a "mvn clean" is done outside of Eclipse, Eclipse will start rebuilding. To avoid this, CloudStack has an Eclipse profile that puts all of the Eclipse generated files in a directory called target-eclipse. In order to activate this, you must do the following to every project. There is a shortcut for the existing projects so please read the shortcut first before deciding to do the following. You still need to perform these steps manually if a new project is added after you ran the shortcut.
CloudStack has a lot of projects so doing the above by hand for every project takes time so here's a shortcut provided for existing projects.
CloudStack has requirement for a newer 1.7 JDK, the default on my Mac was 1.6. You need to download the latest JDK from Oracle JDK Download.
The installation on my Mac was not in the default location: /System/Library/Java/JavaVirtualMachines but in location: /Library/Java/JavaVirtualMachines/.
You can have multiple JRE/JDKs installed on your system, you need to add the path to the new JDK to Eclipse Preferences>Java>Installed JREs
For my JDK, the exact path I programmed was: /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home. Your path may be different depending on the current JDK version.
The Maven integration makes it reasonably easy to run and debug CloudStack through Eclipse. Basically, you can add the 'mvn' command-line calls to your Eclipse Workspace by defining corresponding Run Configurations.
The Maven commands we want to add as Run Configurations are discussed in detail on the How to build CloudStack page. The steps we want to add can be summarised as
Now, we could have combined steps 1 & 2 above, but splitting them allows incremental compilation. In contrast, combining them will make for a very slow build. Also, you only need to setup the database once after doing a Clean.
WRT to debugging: Use the
Jetty-based server lauch. First, tweak this Debug Configuration for source-level debugging: Use Run -> Debug Configurations, and check the
Resolve Workspace Artifacts flag.
For each Run Configuration to be added:
$project_loc:cloudstack(This tells Eclipse that the base directory for execution is the folder with a _pom.xml_ that has an <artifactId> with the value cloudstack)
Maven will download everything needed to run CloudStack with Jetty, build the code, and run the UI. You can connect to it via http://localhost:8080/client.
The following commands were correct at the time of writing. If they don't work, double check the How to build CloudStack page, and if you have any compassion update this section of the wiki.
-pl awsapi jetty:run
You can use Eclipse to attach to the Management Server and debug CloudStack. You setup a Remote Debug Session (Run > Debug Configuration), connect to Port 8787. Typically you would use the project you want to debug as the target and include other projects that you need to debug, e.g. cloud-agent, cloud-api, cloud-core and cloud-server.