Wednesday, 19 October 2016

Backbone JS Simple Application

BackboneJS is a light weight JavaScript library that allows to develop and structure client side applications that run in a web browser. It offers MVC framework which abstracts data into models, DOM into views and bind these two using events.

This example illustrates the Simple Backbone JS application.

The main components of Backbone JS we’ve used here are :
1. Backbone View
2. Backbone Model

At first, we need to include the scripts needed for Backbone JS in the Html file. Underscore JS is the only hard dependency for the Backbone JS.

We can include any other JS libraries if it is necessary. Here we’ve included JQuery which is common.
Let’s look at the "index.html" file. It’s a very basic well known div element with username and password.
As of now, we’ve not separated HTML View part in a different file.

index.html

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
 <title>Backbone Tutorial ONE</title>  
 <script src="js/libs/jquery.js"></script>  
 <script src="js/libs/underscore.js"></script>  
 <script src="js/libs/backbone.js"></script>  
 <script src="js/UserView.js"></script>  
 <script src="js/UserModel.js"></script>  
 <script src="js/main.js"></script>  
 <div id="appArea">  
 <label for="userNameText">Enter User Name :</label><input type="text" id="userNameText">  
 <label for="passwordText">Enter Password :</label><input type="password" id="passwordText">  
 <button id="submitButton">Submit</button>  
 </div>  

Now, create a Backbone View named “UserView.js” for this screen. In the UserView.js file, we’ve added the events and we do have initialize method. Blur event listener added for userNameText field.

UserView.js

 var UserView = Backbone.View.extend({  
  events : {  
  'blur #userNameText':'onUserNameBlur',  
  'click #submitButton':'onSubmit'  
  },  
  onUserNameBlur : function(e){  
  var value = $(e.currentTarget).val().trim();  
  $(e.currentTarget).val(value);  
  },  
  render : function(){  
  //Empty implementation  
  },  
  onSubmit : function(){  
  var userModel = new UserModel();  
  userModel.set("userName",$('#userNameText').val());  
  userModel.set("password",$('#password').val());  
  userModel.save({  
   success : function(response){  
   alert("Success");  
   },  
   error : function(response){  
   alert("Error");  
   }  
  });  
  }  
 });  

In the "UserModel.js" file, just simply added two parameters with userName and password.

UserModel.js

 var UserModel = Backbone.Model.extend({  
  initialize : function(){  
  },  
  defaults : {  
  userName : '',  
  password : ''  
  },  
  url : 'http://localhost:8080/backbone/login'  
 });  

So now we’ve a html file, a Backbone View file and a Backbone Model file. Now we need to execute the methods in UserView.js. In Backbone, events will bind for the elements only in the “el” element.
There are two ways to set el element. Either we can set el : “elementId" or else we can set the element by calling the setElement method. In this example, setElement method is used.

main.js

 $(document).ready(function(){  
  var userView = new UserView();  
  userView.setElement($('#appArea'));  
 });  

Now the el element is set to appArea. So events are binded with those elements.
If Submit button is clicked, onSubmit function will be triggered and Backbone Model will be triggered.

You can download this sample in the following URL. Github

Tuesday, 18 October 2016

Hibernate Mapping

Hibernate is a ORM framework which will map our database tables into our POJO classes. By this, we can do the database operations like insert, update, select and etc. When we come to hibernate mapping, we have the below relationships between entities as in RDBS,
  1. OneToOne
  2. OneToMany
  3. ManyToOne
  4. ManyToOne
We can wire the relationships between our entities by these mappings. We can do these mappings in both the ways, unidirectional and bidirectional. But we just concentrate only on unidirectional mapping here.

Example:
Let's consider we have student database where we have 6 tables named student, student_address, course_details, month_attendance, academic_subject, student_subject.

OneToOne
Each student has one address and each address has one student. So student has one to one relationship with address entity.

OneToMany
We are tracking monthly attendance of every student in month_attendance table. Each student has more than one record in month_attendance. At the same time, one record in month_attendance is associated with only one student. So student has OneToMany relationship with month_attendance.

ManyToOne
Each student has one course, but one course can have more than one student.

ManyToMany
One student can have multiple subjects and one subject can have many students. So this's a ManyToMany relationship.

Please note down the mapping table student_subject which establishes the many to many relationship between student and subject.

Now let's see the below code snippets to know how we wire the relationships between these entities.

Code:
Student.java
 @Entity  
 @Table(name="student")  
 public class Student implements Serializable {  

   @Id  
   @Column(name="student_id")  
   @GeneratedValue(strategy= GenerationType.AUTO)  
   private String studentId;  

   @Column(name="student_name")  
   private String studentName;  

   @Column(name="date_of_birth")  
   private String dob;  

   @OneToOne  
   @JoinColumn(name="student_id")  
   private Address address;  

   @ManyToOne  
   @JoinColumn(name="course_id")  
   private StudentCourse studentCourse;  

   @OneToMany(mappedBy = "monthAttendancePK.studentId")  
   private Set<MonthAttendance> monthAttendances;  

   @ManyToMany  
   @JoinTable(name = "student_subject",joinColumns = @JoinColumn(name = "student_id"),  
       inverseJoinColumns = @JoinColumn(name = "subject_id"))  
   private Set<Subject> subjects;  

   /*  
   *Other properties and mutators  
   */  
 }  

Address.java
 @Entity  
 @Table(name="student_address")  
 public class Address {  
   @Id  
   @Column(name="student_id")  
   private String studentId;  

   private String location;  

   private String city;  

   private String country;  

   /*   
   *Other properties and mutators   
   */   
 }  

Notice the variables location, city, country. We didn't specify the column annotation. Because the variable name and database column name both are same here. So no need to specify it explicitly.

StudentCourse.java
 @Entity  
 @Table(name="course_details")  
 public class StudentCourse implements Serializable {  

   @Id  
   @Column(name="course_id")  
   @GeneratedValue(strategy= GenerationType.IDENTITY)  
   private String courseId;  

   @Column(name="course_name")  
   private String courseName;  

   private String department;  

   @Column(name="class_location")  
   private String classLocation;  

   private String hod;  

   /*   
   *Other properties and mutators   
   */   
 }  

Composite Primary Key:
Creating a entity class for the month_attendance table is quite different from all other entities which we saw above. Because month_attendance has composite primary key means it's a combination of  two different columns, student_id and month_year. So we declare MonthAttendancePK entity, which holds only the primary key columns, along with MonthAttendance entity which holds all column properties other than the primary keys. We will get a better understanding, when we look at the below code.

MonthAttendancePK.java
 @Embeddable  
 public class MonthAttendancePK implements Serializable {  

   @Column(name="student_id")  
   private String studentId;  

   @Column(name="month_year")  
   private String monthYear;  

   /*   
   *Other properties and mutators   
   */   
 }  

The below MonthAttendance class will have this MonthAttendancePK and it's annotated by @EmbeddedId

MonthAttendance.java
 @Entity  
 @Table(name="month_attendance")  
 public class MonthAttendance implements Serializable {  

   @EmbeddedId  
   private MonthAttendancePK monthAttendancePK;  

   @Column(name="percentage")  
   private String percentage;  

   @Column(name="medical_leaves")  
   private String medicalLeaves;  

   @Column(name="planned_leaves")  
   private String plannedLeaves;  

   @Column(name="urgent_leaves")  
   private String urgentLeaves;  

   /*   
   *Other properties and mutators   
   */   

 }  

Please take a note that we didn't use the @Id annotation, when it comes to composite primary key. Let's have a look at the many to many relationship.

Subject.java
 @Entity  
 @Table(name="academic_subject")  
 public class Subject {  

   @Id  
   @Column(name="subject_id")  
   @GeneratedValue(strategy= GenerationType.AUTO)  
   private String subjectId;  

   @Column(name="subject_name")  
   private String subjectName;  

   @Column(name="recommended_books")  
   private String recommendedBooks;  

   /*   
   *Other properties and mutators   
   */   
 }  

We didn't have any entity for the table student_subject. Because it's just a mapping table represents the many to many relationship between student and academic_subject.

SessionFactory:
We can do the database operations through EntityManagerFactory or SessionFactory. EntityManagerFactory is JPA specific API means that it is provided by the Java. Hibernate has the implementation of this API. If we use this EntityManagerFactory, we can easily move between different ORM frameworks. But, In this example, we used hibernate specific SessionFactory. Because hibernate is a more popular and commonly used ORM framework nowadays and it has more features than the JPA specific API. So we don't need to move to different ORM framework. Now let's see how we configured the SessionFactory in ApplicationContext file,

   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">  
     <property name="driverClassName" value="com.mysql.jdbc.Driver" />  
     <property name="url" value="jdbc:mysql://localhost:3306/usersproduct" />  
     <property name="username" value="root"/>  
     <property name="password" value="9may89mysql"/>  
   </bean>  
   <!-- Hibernate 4 SessionFactory Bean definition -->  
   <bean id="sessionFactory"  
      class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  
     <property name="dataSource" ref="dataSource" />  
     <property name="annotatedClasses">  
       <list>  
         <value>com.sample.model.Student</value>  
         <value>com.sample.model.StudentCourse</value>  
         <value>com.sample.model.MonthAttendance</value>  
         <value>com.sample.model.Subject</value>  
         <value>com.sample.model.Address</value>  
       </list>  
     </property>  
     <property name="hibernateProperties">  
       <props>  
         <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>  
         <prop key="hibernate.show_sql">true</prop>  
       </props>  
     </property>  
   </bean>  
   <tx:annotation-driven transaction-manager="transactionManager"/>  
   <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">  
     <property name="sessionFactory" ref="sessionFactory" />  
   </bean>  

We used this SessionFactory in the below dao class to fetch all the students and to fetch a student by the given student id along with address, attendance, course, subject details as we configured the relationships.

StudentDaoImpl.java
 @Repository  
 public class StudentDaoImpl implements StudentDao{  
   @Autowired(required = true)  
   private SessionFactory sessionFactory;  
   public List<Student> listStudents() {  
     Session session = this.sessionFactory.openSession();  
     List<Student> studentList = session.createQuery("from Student").list();  
     return studentList;  
   }  
   public Student getStudentData(String studentId) {  
     Session session = this.sessionFactory.openSession();  
     List<Student> studentList = new ArrayList<Student>();  
     Student student = session.get(Student.class,studentId);  
     return student;  
   }  
 }  


Please Click here to download this project from GitHub.


Sunday, 9 October 2016

JMS Implementation

Java Messaging Service API to send messages between different components. We can see the definition of it in many places.So we’re skipping to define it. We are just going to see the various implementations of sending and receiving messages. As we know, we have two JMS mechanisms, Queue and Topic. Now we will just explore the implementation of JMS queue, not the JMS topic that we will see in the next part of JMS article. This article covers the below,
  1. Message Sending to a queue.
  2. Message Reception from a queue. 
      1. Synchronous Message Reception.
      2. Asynchronous Message Reception.
Note : the examples are based on spring framework.

Message Sending and Synchronous Message Reception:

We need to create jmstemplate in application context. Please see the below application context,
      <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">  
           <property name="brokerURL" value="tcp://localhost:61616" />  
      </bean>  
      <bean id="messageDestination" class="org.apache.activemq.command.ActiveMQQueue" >  
           <constructor-arg value="employee" />  
      </bean>  
      <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">  
           <property name="connectionFactory" ref="connectionFactory" />  
           <property name="receiveTimeout" value="10000" />  
      </bean>  
      <bean id="employeeMsgSender" class="com.employee.proxy.EmployeeMsgSender">  
           <property name="destination" ref="messageDestination" />  
           <property name="jmsTemplate" ref="jmsTemplate" />  
      </bean>  
      <bean id="employeeMsgConsumer" class="com.employee.proxy.EmployeeMsgConsumer">  
           <property name="destination" ref="messageDestination" />  
           <property name="jmsTemplate" ref="jmsTemplate" />  
      </bean>  
Destination represents the queue and the queue name is employee. EmployeeMsgSender and 
EmployeeMsgConsumer will send and receive messages respectively by using this jmstemplate. 
please see below code snippets,

sendEmployeeToQueue method of EmployeeMsgSender,
 public void sendEmployeeToQueue(final Employee employee) {  
           System.out.println("Producer sends " + employee);  
           ObjectMapper objectMapper = new ObjectMapper();  
           String strEmployee = null;  
           try {  
                strEmployee = objectMapper.writeValueAsString(employee);  
           } catch (JsonGenerationException e) {  
                e.printStackTrace();  
           } catch (JsonMappingException e) {  
                e.printStackTrace();  
           } catch (IOException e) {  
                e.printStackTrace();  
           }  
           final String employeeMsg = strEmployee;  
           jmsTemplate.send(destination, new MessageCreator() {  
                public Message createMessage(Session session)  
                          throws JMSException {  
                     return session.createTextMessage(employeeMsg);  
                }  
           });  
      }  

getNewEmployeeMsg method of EmployeeMsgConsumer,
 public Employee getNewEmployeeMsg(){  
           TextMessage textMessage = (TextMessage) jmsTemplate  
                     .receive(destination);  
           String employeeMsg = null;  
           try {  
                employeeMsg = textMessage.getText();  
           } catch (JMSException e1) {  
                e1.printStackTrace();  
           }  
           ObjectMapper objectMapper = new ObjectMapper();  
           Employee employee = null;  
           try {  
                employee = objectMapper.readValue(employeeMsg, Employee.class);  
           } catch (JsonParseException e) {  
                e.printStackTrace();  
           } catch (JsonMappingException e) {  
                e.printStackTrace();  
           } catch (IOException e) {  
                e.printStackTrace();  
           }  
           return employee;  
      }  


MessageConverter:
                      If we want to keep this message conversion separated, we can use MessageConverter. For this, Create a class which implements MessageConverter and implements the methods fromMessage and toMessage.
 public class EmployeeConverter implements MessageConverter{  
      @Override  
      public Object fromMessage(Message arg0) throws JMSException,  
                MessageConversionException {  
           Employee employee = null;  
           ObjectMapper objectMapper = new ObjectMapper();  
           ActiveMQTextMessage activeMQTxtMsg = (ActiveMQTextMessage) arg0;  
           try {  
                String employeeMsg = activeMQTxtMsg.getText();  
                employee = objectMapper.readValue(employeeMsg, Employee.class);  
           } catch (JMSException | IOException e) {  
                e.printStackTrace();  
           }  
           return employee;  
      }  
      @Override  
      public Message toMessage(Object arg0, Session arg1) throws JMSException,  
                MessageConversionException {  
           Employee employee = (Employee) arg0;  
           ObjectMapper objectMapper = new ObjectMapper();  
           String strEmployee = null;  
           try {  
                strEmployee = objectMapper.writeValueAsString(employee);  
           } catch (JsonGenerationException e) {  
                e.printStackTrace();  
           } catch (JsonMappingException e) {  
                e.printStackTrace();  
           } catch (IOException e) {  
                e.printStackTrace();  
           }  
           Message message = arg1.createTextMessage(strEmployee);  
           return message;  
      }  
 }  

Now we don't need to convert the employee object before sending and after receiving. Instead we can directly send the Employee object by convertAndSend method and receive employee object by receiveAndConvert method.Spring will take of converting before sending and after receiving the message by calling the above methods in MessageConverted class. Please see the below code snippets,

convertAndSendEmployee method of EmployeeMsgSender. We can call this method instead of calling the sendEmployeeToQueue method.
 public void convertAndSendEmployee(final Employee employee) {  
       jmsTemplate.convertAndSend(destination,employee);  
 }  

receiveAndConvertEmployee method of EmployeeMsgConsumer. We can use this method instead of the getNewEmployeeMsg method.
 public Employee receiveAndConvertEmployee(){  
      Employee employee = (Employee) jmsTemplate  
                     .receiveAndConvert(destination);  
      return employee;  
 }  

Please Click here to download this example.



Asynchronous Message Reception:

Create a class which implements MessageListener interface and it's onMessage method.
 public class EmployeeMessageListener implements MessageListener {  
      @Override  
      public void onMessage(Message arg0) {  
           Employee employee = null;  
           ObjectMapper objectMapper = new ObjectMapper();  
           ActiveMQTextMessage activeMQTxtMsg = (ActiveMQTextMessage) arg0;  
           try {  
                String employeeMsg = activeMQTxtMsg.getText();  
                employee = objectMapper.readValue(employeeMsg, Employee.class);  
           } catch (JMSException | IOException e) {  
                e.printStackTrace();  
           }  
           System.out.println("Received Employee Object is : "+employee);  
      }  
 }  

Create a message listener container and add this above message listener class as a reference. We also need to pass the connection factory reference and the queue name. Please see the below application context for the better understanding,
      <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">  
           <property name="brokerURL" value="tcp://localhost:61616" />  
      </bean>  
      <bean id="employeeMessageListener" class="com.employee.listener.EmployeeMessageListener"/>  
      <bean id="jmsContainer"  
           class="org.springframework.jms.listener.DefaultMessageListenerContainer">  
           <property name="connectionFactory" ref="connectionFactory" />  
           <property name="destinationName" value="employee" />  
           <property name="messageListener" ref="employeeMessageListener" />  
      </bean>  
When we start your application by instantiating ApplicationContext, this'll start listening to the queue names employee for the incoming message. We can test this by sending message to this queue. The onMessage method will be called when the queue received any message.

Please Click here to download this example.

Please have a look at the message converter, before closing the JMS queue exploration.

Tuesday, 4 October 2016

JBOSS Fuse application or OSGI Bundle example

When we read about OSGI, we get confused by the various terminologies like modular application, dynamic components, microservices, libraries, reusable components, OSGI bundle, features and etc. So here, in this blog, we are not gonna care about it. We'll just see an simple application which can be deployed in JBOSS Fuse.

What are we gonna do?
                     Let's say a user is logging in to an application like amazon or filpkart. You need to fetch and display the products that you want to suggest to the user to purchase, in home page. Our application is a restful web service to get all the products with its id, name, company name.  We are gonna make two jar file, one for rest API and one for the actual service which has the real implementation.

Products module:
                     Let's first look at the actual implementation without the rest API. Later we'll see how to create the rest API jar and how it make use of the actual implementation jar. Click here to download the code base of this module.

How does it differ from the traditional jar or library file?
                     MANIFEST.MF and blueprint.xml are making the differences. Even though we get a jar file while building this project, we call this jar file by the name OSGI bundle, because of these two files.

blueprint.xml
Below is the blueprint.xml of our implementation jar. 


<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

  <bean id="productServices" class="com.flexy.products.services.ProductServicesImpl">
      <property name="productDao" ref="productDao"/>
  </bean>
  
  <bean id="productDao" class="com.flexy.products.repository.ProductDaoImpl"/>
  
  <service ref="productServices" interface="com.flexy.products.services.IProductServices"/>

</blueprint>


Note down this service definition. We will access this service from rest API jar.

MANIFEST.MF
                     Next, the MANIFEST.MF file. We won't have this file in our project. This file will be generated and placed inside the jar under the META-INF folder, while building the application. To add this file in your jar, we should have the below maven plugin in your pom.xml.


<plugin>
 <groupId>org.apache.felix</groupId>
 <artifactId>maven-bundle-plugin</artifactId>
 <version>2.3.7</version>
 <extensions>true</extensions>
 <configuration>
  <instructions>
   <Bundle-SymbolicName>products</Bundle-SymbolicName>
   <Import-Package>
    org.osgi.service.blueprint,
    java.text,
    java.util,
    org.slf4j
   </Import-Package>
   <Export-Package>
    com.flexy.products.services,
    com.flexy.products.model
   </Export-Package>
  </instructions>
 </configuration>
</plugin>


Once we build this module, we get the below MANIFEST.MF file inside the jar.

Manifest-Version: 1.0
Bnd-LastModified: 1475582457289
Build-Jdk: 1.7.0_75
Built-By: arunv
Bundle-ManifestVersion: 2
Bundle-Name: User Products
Bundle-SymbolicName: userproducts
Bundle-Version: 1.0.0.6
Created-By: Apache Maven Bundle Plugin
Export-Package: com.flexy.userproducts.services;uses:="javax.ws.rs,javax
 .jws,com.flexy.products.model,com.flexy.products.services,org.slf4j";ve
 rsion="1.0.0.2"
Import-Package: com.fasterxml.jackson.jaxrs.json;version="[2.4,3)",com.f
 lexy.products.model;version="[1.0,2)",com.flexy.products.services;versi
 on="[1.0,2)",javax.jws,javax.ws.rs;version="[2.0,3)",javax.ws.rs.core;v
 ersion="[2.0,3)",org.osgi.service.blueprint;version="[1.0.0,2.0.0)",org
 .slf4j;version="[1.7,2)"
Import-Service: com.flexy.products.services.IProductServices;multiple:=f
 alse
Tool: Bnd-1.50.0

Service element vs Export-Package:
                     The service element in blueprint.xml and these export packages may look like both have the same responsibilities. But both are completely different and each has its own responsibility. The classes inside the exported packages can be imported in other modules as we do in traditional way. If the class depends on any other class like dependency injection, we have to do this ourselves in our own module. But we can use the service classes without worrying about its implementation and its dependencies.You can get the better clarity when you look at the reference element of blueprint.xml, which we’ll see in a min,

User Product Module:
                     Now we will see how to use this jar file in the rest API jar. Click here to download the code base of this module. 

blueprint.xml
As we mentioned above, this rest API is also a OSGI bundle. Let's look at it's blueprint.xml file.


<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
    xmlns:cxf="http://cxf.apache.org/blueprint/core"
    xsi:schemaLocation="
      http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
      http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
      http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd">
 
 <jaxrs:server id="userProductService" address="/userproducts">
        <jaxrs:serviceBeans>
            <ref component-id="userproducts"/>
        </jaxrs:serviceBeans>
        
        <jaxrs:providers>
           <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
        </jaxrs:providers>
        
    </jaxrs:server>
 
    <cxf:bus>
        <cxf:features>
          <cxf:logging />
        </cxf:features>
    </cxf:bus>
    
  <bean id="userproducts" class="com.flexy.userproducts.services.UserProductServiceImpl">
      <property name="productServices" ref="productServices"/>
  </bean>
  
  <reference id="productServices" interface="com.flexy.products.services.IProductServices"></reference>
  
</blueprint>


The reference element is used to mention the service which we want to use from the dependent jars.
Now we have a question where to mention or configure the dependency jar. That's features.xml and we can also call features repository. We can have n number of features repository and each repository can have n number of feature. feature is again a confusing word. It's nothing but a jar or library or dependency or OSGI bundle.

features repository:
                     We can keep this features.xml file wherever we want, add it in the feature repository. But here, we kept it along with our project. Below is our features.xml,


<?xml version="1.0" encoding="UTF-8"?>
<features name="userproductfeature-1.0.0-1" xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">

 <feature name="products" version="1.0.0-2" resolver="(obr)">
  <bundle dependency="true">mvn:com.flexy/products/1.0.0-2</bundle>
 </feature>

</features>


Summarizing the items which we should note it down,
features.xml - feature or dependency repository to specify the dependent jar.
META-INF/MANIFEST.MF
                     Import packages - to specify the dependent packages.
                     Export packages - classes inside the packages can be used by other bundles or jars.
blueprint.xml
                     service - registering a service in the OSGI service registry. This service can be accessed by other OSGI bundles using reference element.
                     reference - find the service in service registry and get the bean.

There are lot to know about the deployment and advantages of it. But adding too much in a single article will make us tired. So we will try to explore more and publish more in the next article.

For Javascripts, visit http://flexydevcenter.blogspot.com/