Making Struts Application to run as OSGI plugin

Introduction of OSGI

OSGi stands for “Open Services Gateway initiative”. The OSGi technology is a set of specifications that define a dynamic component system for Java. These specifications enable a development model where applications are (dynamically) composed of many different (reusable) components.

Formed in 1999, the OSGi alliance made its first steps into the Java market within the embedded device segment. Years later it further extended its reach to Java desktop projects, providing a major foundation for the modularity and extensibility of the Eclipse open-source IDE project. Now, as the service’s era is dawning, OSGi is stepping into its latest Java frontier: the server side.

Like many other alliances in the tech industry, OSGi’s best practices and development policies are dictated by consensus among its many member companies. And in the case of OSGi’s server-side presence, numerous prominent Java vendors have already started shifting their SOA product lines around OSGi blueprints, one such case being BEA’s own microService Architecture (mSA), which relies on OSGi for its backplane components.

OSGi Key Concepts

With much of OSGi’s principles successfully applied to everything from smart phones to IDEs (Integrated Development Environments), it can be difficult to sum up every OSGi aspect in a few sentences; however, the following key concepts should be enough to give you a feel for OSGi’s overall place in the Java ecosystem:

  • The environment and framework: OSGi is often categorized as a Java framework. However, don’t let this often overused word in the Java world cause you to pigeonhole OSGi as one of the hundreds of frameworks now available to ease everything from Java Web development to Java testing. OSGi crosses this boundary, effectively providing an ad-hoc environment that facilitates modularizing an application into smaller and more manageable pieces.
  • The JVM companion: Since OSGi’s roots are in the embedded market, it should come as no surprise that OSGi’s primary focus is on boosting the capabilities of the lowest common denominator in Java: The Java Virtual Machine. While the JVM has more than a decade of engineering behind it, for certain tasks—such as system services and dynamic loading—it has fallen shy of the expected curve in some vertical industries, giving way to initiatives like OSGi to fill in feature gaps.
  • The Java packaging bundle: Of course, no environment or framework is exempt from having its own packaging model, so just as you may have become accustomed to dealing with WAR (Web Archives) and EAR (Enterprise Archives) while working with Java EE applications, or the more general purpose JAR (Java Archives) on your Java projects, so too OSGi has its own packaging model, which goes by the name of a “bundle.” For now, don’t worry too much about what makes up a bundle—we will get to that in a little while—just be aware that the term “bundle” practically goes hand in hand with OSGi.

Creating struts example plugin project

  • Make an empty project of plugin type in eclipse and then put above downloaded zip file following contents at following location of this new project.
  • src contents into project src folder.
  • \META-INF\manifest.mf file into the project Meta-INF folder
  • .web folder at the project root
  • Add all jar files in web/lib in java build libraries.
  • Add web/WEB-INF/classes at the java build class path
  • build.properties file located at the root of the project should have following contents:

output.. = bin/

bin.includes = META-INF/,\

.,\

web/

source.. = src/

    After creating this plugin project you would need to add its dependency in the build path of the struts project. Now you can compile whole project successfully without any errors.  

    Running the project in the OSGI container

    Running this project is quite easy. All you need is to right click on the project then select Run As–>OSGIFramework as shown below:
    osgistrutspic2

    When you run this application first time, you would be presented following screen:

    osgistrutspic3

    At this screen check org.eclipse.equinox.struts.example as show in red circle in above diagram. Then click Run button. This would start OSGI container with struts plugin already installed in it. You would need to type ss at OSGI prompt as shown below to see your plugin in the list:

    osgistrutspic4

     

    You will see that org.eclipse.equinox.struts.examples in the list with status active. Congratulation you have successfully deployed the struts OSGI application. Now you can browse this struts example application using browser. The default port is 80 of the jetty server that is embedded in equinox, so you would need to type following URL to run this application:

    http://localhost:80/struts-examples/welcome.do

    Follow ups :

    Here is my second post on how to deploy this application as standalone app for distribution 

    https://imamraza.wordpress.com/2009/02/09/deploying-osgi-web-application-as-standalone-application/

    Advertisements

    5 thoughts on “Making Struts Application to run as OSGI plugin

    1. Hi Imam,
      Great work… I did all the things. But i am getting the bundle status as,

      922 RESOLVED org.eclipse.equinox.struts.examples_1.0.0

      osgi>

      Any help to run this application would be regreted……

      Thanks in advance

    2. Hi Imam,

      bundle isa active, but how to deploy on server i have tomcat already installed. To run on jetty server, is anything there to do? Please help me…..

    3. Hi, While running the application in tomcat the following exception raised

      Missing Constraint: Import-Package: org.w3c.dom.traversal; version=”0.0.0″

    4. Hi, While running the application in tomcat the following exception raised
      When starting the bundle “32 INSTALLED com.springsource.javax.servlet.jsp.jstl_1.2.0″
      Missing Constraint: Import-Package: org.w3c.dom.traversal; version=”0.0.0”

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s