Add log4j to RCP application

log4j is always one of the best logging frameworks available. But, adding a log4j framework in RCP application can be quite a hectic sometime, because we need to add the references in many files and many places. Also, while working on my own, it tooks me a few hours to figure what they are! So, I decided to sum them up in this tutorial.

So, let us start adding log4j framework in RCP application.

Step 1: Obviously the first step is downloading latest version of log4j.jar. I downloaded  log4j-1.2.17.jar. Save the jar inside a folder (namely lib) in side the workspace.

Step 2: Next step is to create a log4j.properties. I am  not going in to the detail of how to create one. Rather I will use a simple template for that.

My journey from Plugin-based to Feature-based RCP application

While adding log4j to my own RCP application, I came across many issues (Surely I will discuss in the coming posts how to add log4j to a RCP application), but one them was that- I was not using feature based RCP application. My application was pure plugin based, and so was the product.

But, for using log4j in the application,  it was a must that I export log4j.properties  in the exported product. While doing that, I came to know that it is impossible to customize the export process . In simple words, it is not possible to export some custom file while exporting a RCP plugin based product.

So, I switched to feature based RCP application. It seemed to me at the beginning that it's a heck of work, but, later I realized it will hardly take 10 minutes to do this. Before that, if you are not sure how to create RCP application, check this post - Create a Simple RCP Application

So, let's start!!

Step 1: Create a new feature project. Click File ->  New -> Other -> Plugin-Development -> Feature Project.

Accessing files inside a project without hardcoded file path

Last week while working , I had to access some icon file which was present in my workspace. Whiel accessing it using hard coded path, I was able to access it perfectly. But, I was unable to find the relative path of that file.
I almost wasted 1 whole day!!

Well, after wasting 1 whole day, this is what I came up with... A simple one liner... A permanent solution for this kind of problems. And, I wanted to document it somewhere, so that I won't again waste hours.

TreeViewer in RCP

This tutorial is about creating a Tree using RCP and displaying it. I intend to create a small tree in RCP here which will look like -

Root
        Child 1
                   Child 1_1
                   Child 1_2
        Child 2

So, let' start step by step.

Step 1.

Create a Simple RCP application and add a view to it. If you don't know how to do it, please refer to these tutorials  - Creating a simple RCP application and Adding a view to RCP application. In this example, I have named the view class TreeViewClass.java