Third Party Jars and Libraries Plugin - Documentation topics on: 3rd party,jars,lib,osgi,.

Third Party Jars and Libraries Plugin

This plugin is an example of how to add 3rd party jars to a bundle plugin.

How to create a bundle plugin with external jars

Let’s review the file organization on the 3rd Party ( example:

META-INF/MANIFEST.MF: The manifest file is very important for the deployment, it lists the Bundle Name, Version and Packages.

In this MANIFEST you must specify (see template plugin):

  • Bundle-Name: The name of your bundle
  • Bundle-SymbolicName: A short an unique name for the bundle
  • Bundle-Activator: Package and name of your Activator class (example: com.dotmarketing.osgi.external.Activator)
  • Bundle-ClassPath: The Bundle-ClassPath specifies where to load classes from from the bundle.
  • This is a comma separated list of elements to load (such as current folder,lib.jar,other.jar).
  • (example: .,lib/date4j.jar )
  • DynamicImport-Package: * Dynamically adds required imports the plugin may need without adding them explicitly
  • Import-Package: This is a comma separated list of package's name. List the packages that you are using inside the bundle plugin and that are exported by dotCMS.



In order to work inside the Apache Felix OSGI runtime, the import and export directive must be bidirectional.

In dotCMS you must declare the set of packages that will be available to the OSGI plugins by changing the file: dotCMS/WEB-INF/felix/osgi-extra.conf.
This is possible also using the dotCMS UI (System -> Dynamic Plugins -> Exported Packages).

Only after that exported packages are defined in this list, a plugin can Import the packages to use them inside the OSGI blundle.


Include all third party libraries to be used on your dynamic plugin to the lib folder under the bundle's root directory.

$ pwd
$ ls


Under the src folder you will find a Java class that utilizes the 3rd party library:

$ pwd
$ ls -l
-rw-r--r-- 1
-rw-r--r-- 1


Sample Class that creates methods that use the 3rd party library that was added to the lib folder of the bundle (lib/date4j.jar).

import hirondelle.date4j.DateTime;


This bundle activator extends from com.dotmarketing.osgi.GenericBundleActivator and implements BundleActivator.start().

Calls the Examples class static methods to run simple tests that use the 3rd party library date4j.jar


After building and loading the dynamic plugin, you will find the following messages in the log: catalina.out if the bundle loaded correctly.

Current date-time in default time zone : 2012-10-08 11:20:02
Current date-time in Cairo : 2012-10-08 20:20:02 (Monday)
Age of someone born May 16, 1995 is : 17
The 3rd Friday of this month is : 2012-10-19
Number of days till Christmas : 78
90 days from today is : 2013-01-06
3 months and 5 days from today is : 2013-01-13
Numbers of hours difference between Paris and Perth : 6
The number of weeks since Sep 6, 2010 : 109
This many seconds till midnight : 45598
Output using an ISO format: 2012-10-08T11:20:02
The first day of this week is : 2012-10-07
The number of years the JDK date-time API has been suctorial : 16