Integrating Felix with NetBeans has been edited by Richard S. Hall (Sep 02, 2008).

(View changes)

Content:

Integrating Felix with NetBeans

This document explains how to launch Felix inside of the Netbeans IDE. Then, it will be possible to use Netbeans debugging and profiling facilities on bundles.

Preliminaries

To integrate Felix inside of Netbeans, you need Felix and NetBeans and nothing else.

Installing Netbeans

First, you need Netbeans. To download the Netbeans IDE go to http://download.netbeans.org/netbeans/6.1/final/ . This tutorial was done using Netbeans 6.1 but it should work on Netbeans 6.0.

Creation of the Felix binaries

To integrate Felix inside of Netbeans, you have two options:

  1. Integrating the Felix release as a Java project. This is what we are going to cover in this tutorial.
  2. Integrating the Felix release using the Maven plugin. But this option has issues that can be resolved but it takes a little more work. This will be covered in another tutorial for those that really want to pursue it.

Using the Felix release as a Java Project

Once, Netbeans is installed, you need to download Felix. You will find the Felix releases at http://felix.apache.org/site/downloads.cgi . Choose a binary release in your preferred archive format. Then, unzip the release in a temporary directory. We will copy the files into our project later.

Building and Using Felix Trunk

If you want to use the Felix trunk, follow the instructions located here http://felix.apache.org/site/building-felix.html to checkout and build it. The Felix binaries are created in the main project (directory). We will copy these files into our project later.

Using Felix with NetBeans

This integration tutorial uses a Java project for the integration. This new project will contain Felix. In the following sections it will be explained how-to do this.

Creation of the Felix Java project

First launch Netbeans. Then click on File->New->Project... as shown in Figure 1

This action will launch the project creation wizard. From the Categories list choose Java and from the projects list choose Java Application as shown in Figure 2 then press the "Next >" button.

Enter the project name (Felix for example), select your project directory, and uncheck the "Create Main Class" check box then press the finished button. See Figure 3

Copying Felix to the newly created project

Now, remember where you uncompressed the Felix release, or where the Felix main project is. Move or copy these files to your project directory. You can do this any way that is easiest for you. On my Linux box I do something like this from the location where I built Felix:
cp -r ./* /project path/
Where project path is the path to your project directory.
Once you have Moved or copied the files Collapse and expand the project. This will make Netbeans refresh the project. If that does not work for you (on Netbeans 6.0 it may not) just close and open it.

Preparing the Felix Project

The first thing you will notice is that our new project has a red exclamation point on it. What this means is that when Netbeans parsed the java files it could not find all the library dependencies so lets fix that up.
Right-click on the just created project and select the properties as shown in Figure 4

This will bring up the project properties dialog. Select Libraries as shown in Figure 5

Now we want to press the "Add JAR/Folder" button and navigate to your project directory/bin and select the Felix.jar as shown in Figure 6. NOTE: Make sure the "Use Relative Path:" Radio button is selected. Then press the Open button.

Your Libraries panel should now look like what is shown in Figure 7. You can now press the OK button.

At this point the red exclamation point should should disappear and now we can run Felix. Right click on the project node and select the Run menu item as shown in Figure 8

When you do this the Run Project dialog will pop-up with a list of all class files with a main method defined. In our case this will only show the org.apache.felix.main.Main class so we select that and press the ok button. The Run Project dialog is shown in Figure 9

After you press the OK button in the Run Project dialog Felix will be launched and the output window will open with the Felix command line tool running as shown in Figure 10
At this point you can enter your preferred profile and interact with Felix as if you had launched Felix from a command line shell.

Re-launching Felix

Now that our project is all setup all you have to do to re-launch Felix is select the Run menu item from the project context menu. Or if you prefer if you set Felix as the Main project you can use the Run Menu on the main menubar.

Felix Configuration

At this point you may want to make some changes to the way Felix is configured. In Netbeans you will have to open the Files View. Expand the Felix folder and then the conf folder as shown in Figure 11 NOTE: When you see this the first time the cache folder will not be there. If you decide to make the configuration changes shown in the next section then it will be created the next time you run Felix.

Configure the Felix cache location

Felix stores profiles and deployed bundles inside a cache. Normally this cache is located at $userhome/.felix It is possible to change this location in order to clean it quickly and also to keep your development cache separated from other felix based applications you may be running on your computer. You may also want to set a default profile so you don't have to enter it every time you launch Felix.

Open the configuration file (config.properties). Then, add a new line with felix.cache.dir=cache(Figure 12). And if you want to set a default profile uncomment the felix.cache.profile="" line and change it to what you want (Figure 12). To clean your cache, just delete the cache directory.

The next time you run Felix the cache directory will be created with in your project. To verify that it did or if you want to clean it use the File view and expand the Felix folder you should now see a cache folder that was not there before. You can refer to Figure 11 to see this as I had already ran Felix again before taking the screen shoot.

Add auto-started bundles

Often you will want Felix to automatically deploy some bundles that you need for your development. You can do this by modifying the felix.auto.start.1 (or 2) property in the config.properties file.
When editing this property the bundles can be relative or absolute file paths to the bundles you want to auto load. Also don't forget to put the line continuation marker "\" and the end of each line except the last one. In figure 13 you can see the default configuration that is shipped with Felix.

Debugging bundles

Now that we are able to launch Felix as a Java Application we can use the debugging and profiling features built into Netbeans. Future tutorials will go into more detail on how to do this.

Conclusion

This document has presented one way in which you can integrate Felix inside of Netbeans. For any questions or feedback, feel free to send an email to rdjackson at gmail dot com or on the Felix mailing list users at felix dot apache dot org

Reply via email to