{"id":23646,"date":"2015-07-16T11:00:35","date_gmt":"2015-07-16T08:00:35","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=23646"},"modified":"2019-04-03T14:01:11","modified_gmt":"2019-04-03T11:01:11","slug":"gradle-osgi-plugin-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/","title":{"rendered":"Gradle OSGi Plugin Example: BNDTools Bundle Integration"},"content":{"rendered":"<p>In this example&nbsp;we will talk about how to integrate OSGi frameworks with Gradle build&nbsp;tool. This work consists in build JAR files and customizing Manifest file through Gradle build Script and Deploying them in a OSGi Container like Apache Felix.<\/p>\n<h2>1. Introduction to Gradle and OSGi Integration<\/h2>\n<p>Gradle is an automatic build tool of more use today, so it&#8217;s almost necessary to integrate the different types of projects with Gradle, to automate the process of build and liberation. In this example we will see how using Gradle can compile, build, install and run a bundle in an OSGi environment. The main goal is to understand Gradle integration with OSGi BND tools.\n<\/p>\n<h3>1.1 Basic Concepts<\/h3>\n<p>There are some basic concepts that we must check before starting the example.<\/p>\n<ul>\n<li><strong>Gradle:<\/strong> Our tool to build and automate the process.<\/li>\n<li><strong>OSGi: <\/strong>It&#8217;s the framework to make Java Modular applications and the environment where to deploy.<\/li>\n<li><strong>BND Tools:<\/strong> It&#8217;s a framework or library pack, that makes OSGi development process more friendly and give to us a lot of capabilities to customize out OSGi bundles. OSGi and BND Tools are required each other.<\/li>\n<li><strong>Gradle-Osgi Plugin:<\/strong> It&#8217;s a Gradle Plugin developed by Renato Athaydes to make the OSGi integration easier.<\/li>\n<li><strong>Apache Felix, Eclipse Equinox:<\/strong>&nbsp;Are the main OSGi implementations, are containers to deploy OSGi bundles. Think in OSGi bundles like a war file and Apache Felix like Tomcat container.<\/li>\n<\/ul>\n<p>I want to make this example so simple, so we start.<\/p>\n<h2>2. What do We Need?<\/h2>\n<ul>\n<li>IDE: Eclipse Luna 4.4, you can download <a href=\"https:\/\/www.eclipse.org\/downloads\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a><\/li>\n<li>Gradle 2.x or superior,&nbsp;you can download Gradle 2.5 <a href=\"https:\/\/gradle.org\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a><\/li>\n<li>Java JDK 1.7_75 or superior, download <a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/jdk7-downloads-1880260.html\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a><\/li>\n<li>BND Tools 2.4, this is a Eclipse Plugin that we can download in Eclipse Marketplace<\/li>\n<li>Gradle-Osgi Plugin, you can get more detail <a href=\"https:\/\/github.com\/renatoathaydes\/osgi-run\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a><\/li>\n<\/ul>\n<h2>3. Environment Configuration<\/h2>\n<p>To make simpler the example, we assume that you have already installed your Eclipse, JDK, Gradle and environment variables for both tools (JAVA_HOME and GRADLE_HOME).<\/p>\n<p>How to Install OSGi?<\/p>\n<p>It&#8217;s the most simple installation ever, you only need to download Eclipse! Eclipse is one the projects that use OSGi for your development and release process, so OSGi, Equinox and Felix frameworks are already installed as Eclipse&#8217;s plugins.<\/p>\n<p>Next Step, Install BND Tools Eclipse Plugin.<\/p>\n<p>Please download and install from Eclipse Marketplace using the menu: Help &gt; Eclipse Marketplace &gt; type &#8220;bndtools&#8221;.<\/p>\n<p><figure id=\"attachment_25062\" aria-describedby=\"caption-attachment-25062\" style=\"width: 711px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/bndtoolsinstall.jpg\"><img decoding=\"async\" class=\"size-full wp-image-25062\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/bndtoolsinstall.jpg\" alt=\"BND Tools Eclipse Plugin installation\" width=\"711\" height=\"685\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/bndtoolsinstall.jpg 711w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/bndtoolsinstall-300x289.jpg 300w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><\/a><figcaption id=\"caption-attachment-25062\" class=\"wp-caption-text\">BND Tools Eclipse Plugin installation<\/figcaption><\/figure><\/p>\n<h2>4. Creating OSGi Project<\/h2>\n<p>Create a new OSGi bundle project using File &gt; New &gt; Other &gt; Bndtools &gt; Bndtools OSGi project<\/p>\n<p><figure id=\"attachment_25063\" aria-describedby=\"caption-attachment-25063\" style=\"width: 721px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/osgiBndToolsProject.jpg\"><img decoding=\"async\" class=\"size-full wp-image-25063\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/osgiBndToolsProject.jpg\" alt=\"BND Tools OSGi Project\" width=\"721\" height=\"562\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/osgiBndToolsProject.jpg 721w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/osgiBndToolsProject-300x234.jpg 300w\" sizes=\"(max-width: 721px) 100vw, 721px\" \/><\/a><figcaption id=\"caption-attachment-25063\" class=\"wp-caption-text\">BND Tools OSGi Project<\/figcaption><\/figure><\/p>\n<p>Then, type a project&#8217;s name and keep all the other settings as they are, then click next to choose project template, in this case, we use OSGi component development by default.<\/p>\n<p><figure id=\"attachment_25065\" aria-describedby=\"caption-attachment-25065\" style=\"width: 614px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/osgi-project-template.jpg\"><img decoding=\"async\" class=\"size-full wp-image-25065\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/osgi-project-template.jpg\" alt=\"OSGi Project Template\" width=\"614\" height=\"675\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/osgi-project-template.jpg 614w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/osgi-project-template-273x300.jpg 273w\" sizes=\"(max-width: 614px) 100vw, 614px\" \/><\/a><figcaption id=\"caption-attachment-25065\" class=\"wp-caption-text\">OSGi Project Template<\/figcaption><\/figure><\/p>\n<p>So, when we create the first OSGi project, bnd tools ask to create a cnf project, that will store all OSGi configuration and libraries downloaded from external repositories. Only click next and leave all configurations by default, at the end we have 2 projects cnf (bnd tools configuration) and our Gradle OSGi project.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><figure id=\"attachment_25067\" aria-describedby=\"caption-attachment-25067\" style=\"width: 701px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/bnd-tools-cnf-project.jpg\"><img decoding=\"async\" class=\"size-full wp-image-25067\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/bnd-tools-cnf-project.jpg\" alt=\"BND Tools CNF Project\" width=\"701\" height=\"569\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/bnd-tools-cnf-project.jpg 701w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/bnd-tools-cnf-project-300x244.jpg 300w\" sizes=\"(max-width: 701px) 100vw, 701px\" \/><\/a><figcaption id=\"caption-attachment-25067\" class=\"wp-caption-text\">BND Tools CNF Project<\/figcaption><\/figure><\/p>\n<p>Then, define a package for the Bundle Activator and create a new class, we call HelloActivator.java<\/p>\n<p><figure id=\"attachment_25071\" aria-describedby=\"caption-attachment-25071\" style=\"width: 772px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Gradle-OSGi-BundleProject2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-25071\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Gradle-OSGi-BundleProject2.jpg\" alt=\"Gradle OSGi BundleProject\" width=\"772\" height=\"434\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Gradle-OSGi-BundleProject2.jpg 772w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Gradle-OSGi-BundleProject2-300x169.jpg 300w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/a><figcaption id=\"caption-attachment-25071\" class=\"wp-caption-text\">Gradle OSGi BundleProject<\/figcaption><\/figure><\/p>\n<p><span style=\"text-decoration: underline\"><em>HelloActivator.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.gradle.osgi;\n\nimport org.osgi.framework.BundleActivator;\nimport org.osgi.framework.BundleContext;\n\npublic class HelloActivator implements BundleActivator {\n\tprivate BundleContext context;\n\n\tpublic void start(BundleContext context) throws Exception {\n\t\tSystem.out.println(\"Hello JCG, Welcome to OSGi World!!\");\n\t\tthis.context = context;\n\t}\n\n\t\/*\n\t * (non-Javadoc)\n\t * \n\t * @see\n\t * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)\n\t *\/\n\tpublic void stop(BundleContext context) throws Exception {\n\t\tSystem.out.println(\"Goodbye JCG\");\n\t\tthis.context = null;\n\t}\n\n}\n<\/pre>\n<h2>5. Deploying&nbsp;OSGi Project<\/h2>\n<p>The last step before injects Gradle is to deploy the Bundle in an OSGi container, in this example we use Apache Felix. To make possible this, we need to configure bnd.bnd file.<\/p>\n<p>Define a version number, choose the Activator that we&nbsp;created before. In the Export Packages please choose the green plus sign, and add the main package that contains the Activator.<\/p>\n<p><figure id=\"attachment_25079\" aria-describedby=\"caption-attachment-25079\" style=\"width: 857px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/OSGi-Bundle-Content.jpg\"><img decoding=\"async\" class=\"size-full wp-image-25079\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/OSGi-Bundle-Content.jpg\" alt=\"OSGi-Bundle-Content\" width=\"857\" height=\"518\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/OSGi-Bundle-Content.jpg 857w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/OSGi-Bundle-Content-300x181.jpg 300w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><\/a><figcaption id=\"caption-attachment-25079\" class=\"wp-caption-text\">OSGi Bundle Content<\/figcaption><\/figure><\/p>\n<p>In the Run Tab, we must configure 3 options.<\/p>\n<ul>\n<li>Core Runtime, establish the OSGi Framework and JDK to execution, for this case choose Apache Felix 4.0.3 and Java 1.7.<\/li>\n<li>Run Requirements, add all 4 bundles that appears in the caption, project itself (GradleOSGiProject in this case), osgi.cmpn, felix.command and felix.shell.<\/li>\n<li>In the bottom of the Run tab, add the same bundles at Run Bundles configuration<\/li>\n<\/ul>\n<p><figure id=\"attachment_25077\" aria-describedby=\"caption-attachment-25077\" style=\"width: 850px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/OSGi-run-bnd-tools.jpg\"><img decoding=\"async\" class=\"size-full wp-image-25077\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/OSGi-run-bnd-tools.jpg\" alt=\"OSGi Run BND Tools\" width=\"850\" height=\"551\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/OSGi-run-bnd-tools.jpg 850w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/OSGi-run-bnd-tools-300x194.jpg 300w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/a><figcaption id=\"caption-attachment-25077\" class=\"wp-caption-text\">OSGi Run BND Tools<\/figcaption><\/figure><\/p>\n<p>Finally, we can run the project using Run OSGi button in Run tab of bnd.bnd file, so this is the output. We can see the installed bundles typing <code>lb<\/code> on Apache Felix Gogo Shell, so when we start or stop OSGiGradle Bundle, <code>start<\/code> and <code>stop<\/code> Activator&#8217;s methods are executed.<\/p>\n<pre class=\"brush:bash highlight:[9]\">Hello JCG, Welcome to OSGi World!!\n____________________________\nWelcome to Apache Felix Gogo\n\ng! lb\nSTART LEVEL 1\n   ID|State      |Level|Name\n    0|Active     |    0|System Bundle (4.4.1)\n    1|Active     |    1|GradleOSGiProjectIntegration (1.0.0.201507130549)\n    2|Active     |    1|Apache Felix Gogo Command (0.14.0)\n    3|Active     |    1|Apache Felix Gogo Runtime (0.12.1)\n    4|Active     |    1|Apache Felix Gogo Shell (0.10.0)\ng! \n<\/pre>\n<h2>6. Gradle Integration<\/h2>\n<p>To &#8220;Gradlify&#8221; the OSGi Project we need to create a Gradle Build script and configure it correctly. So, create a new File in root project, New &gt; File &gt; type name &#8220;build.gradle&#8221;.<\/p>\n<p>This is the file, so we&#8217;ll look in detail each instruction.<\/p>\n<p><span style=\"text-decoration: underline\"><em>build.gradle<\/em><\/span><\/p>\n<pre class=\"brush:java\">\/*\n * Author: Andres Cespedes\n * Date: 01 July 2015\n * Example: Gradle OSGi Integration Example\n * Site: www.javacodegeeks.com\n * *\/\nbuildscript {\n\trepositories {\n\t\tjcenter()\n\t\tmavenCentral()\n\t}\n\tdependencies {\n\t\tclasspath \"com.athaydes.gradle.osgi:osgi-run-core:1.2\"\n\t}\n}\n\n\/\/ repositories to download external files, like apache felix\nrepositories {\n\tjcenter()\n\tmavenCentral()\n}\n\n\/\/ java version source compatibility\nsourceCompatibility = 1.7\n\napply plugin: 'osgi-run'\n\n\/\/ osgi-run plugin task that add OSGi subprojects as a bundle files to deploy.\nrunOsgi {\n  bundles += subprojects\n}\n\njar {\n    manifest { \/\/ Manifest.MF file customization\n        instruction 'Private-Package','com.javacodegeeks.gradle.osgi'\n        instruction 'Bundle-Vendor', 'JavaCodeGeeks'\n        instruction 'Bundle-Description', 'First OSGi Bundle Created By Gradle JCG Tutorial'\n        instruction 'Bundle-Activator', 'com.javacodegeeks.gradle.osgi.HelloActivator'\n        instruction 'Bundle-ManifestVersion', '2'\n        instruction 'Bundle-Version', '1.0.0.${tstamp}'\n        instruction 'Bundle-Name', 'GradleOSGiProjectIntegration'\n        instruction 'Bundle-SymbolicName', 'GradleOSGiProjectIntegration'\n        instruction 'Export-Package', 'com.javacodegeeks.gradle.osgi;version=\"1.0.0\";uses:=\"org.osgi.framework\"'\t\n    }\n}\n<\/pre>\n<p>The first part <code>buildscript<\/code>, define the repositories and dependencies to import Gradle Bnd OSGi Plugin. In line 18, we set repositories to download and import external libraries to Gradle, this part it&#8217;s important as some think they just simply repositories defined in the <code>buildscript<\/code> block, are necessary to get libraries like apache felix, these libraries are downloaded to &#8216;%USER_HOME%\\.gradle\\caches\\modules-2\\files-2.1&#8217; directory.[ulp id=&#8217;1om4ygalA6VlPl7R&#8217;]<\/p>\n<p>In line 20, apply the external OSGi plugin developed by Renato Athaydes, because Gradle&#8217;s official plugin doesn&#8217;t add value at all, don&#8217;t adds tasks more than customize the Manifest.<\/p>\n<p>Line 23 and 27 are the main part of the script, then we add the project to the bundles to deploy and then can configure OSGi Manifest, each Manifest property is added as instruction, you can check OSGi documentation for available properties.<\/p>\n<h2>7. Running Gradle OSGi Integration<\/h2>\n<p>This is how integration works.<\/p>\n<p>Select build.gradle file and press Ctrl+Alt+D to open windows command shell, then execute this Gradle command to run the OSGi environment.<code>gradle runOsgi<\/code> or <code>gradle rO<\/code> as shortened way.<\/p>\n<pre class=\"brush:bash highlight:[21]\">Microsoft Windows [Versi\u00f3n 6.3.9600]\n(c) 2013 Microsoft Corporation. Todos los derechos reservados.\n\nC:\\Users\\Andres\\workspaceLuna\\GradleOSGiProject&gt;gradle rO\n:GradleOSGiProject:compileJava UP-TO-DATE\n:GradleOSGiProject:processResources UP-TO-DATE\n:GradleOSGiProject:classes UP-TO-DATE\n:GradleOSGiProject:jar\n:GradleOSGiProject:createOsgiRuntime\n:GradleOSGiProject:runOsgi\n____________________________\nWelcome to Apache Felix Gogo\n\n&gt; Building 83% &gt; :GradleOSGiProject:runOsgilb\ng! START LEVEL 1\n   ID|State      |Level|Name\n    0|Active     |    0|System Bundle (4.4.0)\n    1|Active     |    1|Apache Felix Gogo Command (0.14.0)\n    2|Active     |    1|Apache Felix Gogo Runtime (0.12.1)\n    3|Active     |    1|Apache Felix Gogo Shell (0.10.0)\n&gt; Building 83% &gt; :GradleOSGiProject:runOsgiinstall file:..\/GradleOSGiProject.jar\n\ng! Bundle ID: 4\n&gt; Building 83% &gt; :GradleOSGiProject:runOsgi\n<\/pre>\n<p>When apache felix gogo shell is active, type <code>lb<\/code> to see all available Bundles, if your bundle don&#8217;t appears yet, so let install it, how? Execute this simple command <code>install file:..\/GradleOSGiProject.jar<\/code>, obviously considering the name of your jar; apache gogo shell will tell you the Bundle ID, in this case is 4.<\/p>\n<h2>8. Testing Gradle OSGi<\/h2>\n<p>Gradle already setup OSGi environment, so, executing apache gogo shell commands we can interact in Gradle thread with the OSGi Bundle, updating Manifest or Activator itself.<\/p>\n<p><figure id=\"attachment_25155\" aria-describedby=\"caption-attachment-25155\" style=\"width: 785px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/test-gradle-osgi-integration.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/test-gradle-osgi-integration.jpg\" alt=\"Testing Gradle OSGi Plugin\" width=\"785\" height=\"396\" class=\"size-full wp-image-25155\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/test-gradle-osgi-integration.jpg 785w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/test-gradle-osgi-integration-300x151.jpg 300w\" sizes=\"(max-width: 785px) 100vw, 785px\" \/><\/a><figcaption id=\"caption-attachment-25155\" class=\"wp-caption-text\">Testing Gradle OSGi Plugin<\/figcaption><\/figure><\/p>\n<p>Then, if we modify any artifact or java file only executing <code>update BundleID<\/code> in Gradle OSGI environment shell, in this case <code>update 5<\/code> we get updated Bundle, if we start or stop the Bundle can get updated messages.<\/p>\n<p>For the last part of this example, the Manifest is printed in console executing <code>headers BundleID<\/code> command, <code>headers 5<\/code>, useful to compare the deployed Bundle with Gradle Manifest configuration.<\/p>\n<pre class=\"brush:bash\">&gt; Building 83% &gt; :GradleOSGiProject:runOsgiheaders 5\ng!\nGradleOSGiProject (5)\n---------------------\nBnd-LastModified = 1436938982133\nBundle-Activator = com.javacodegeeks.gradle.osgi.Activator\nBundle-ManifestVersion = 2\nBundle-Name = GradleOSGiProject\nBundle-SymbolicName = GradleOSGiProject\nBundle-Version = 1.0.0.201507150543\nCreated-By = 1.7.0_67 (Oracle Corporation)\nExport-Package = com.javacodegeeks.gradle.osgi;version=\"1.0.0\";uses:=\"org.osgi.f\nramework\"\nImport-Package = org.osgi.framework;version=\"[1.3,2)\"\nManifest-Version = 1.0\nPrivate-Package = com.javacodegeeks.gradle.osgi\nRequire-Capability = osgi.ee;filter:=\"(&amp;(osgi.ee=JavaSE)(version=1.7))\"\nTool = Bnd-2.4.1.201501161923\n&gt; Building 83% &gt; :GradleOSGiProject:runOsgi\n<\/pre>\n<h2>9. Key Points<\/h2>\n<div class=\"tip\">\n<p><strong>Tips<\/strong><\/p>\n<ul>\n<li>Gradle Official plugin is poor to support OSGi integration<\/li>\n<li>Key point to Gradle-OSGi integration is to know how to install external bundles<\/li>\n<li>Unofficial Gradle Run Osgi Bundle plugin facilitates the integration process, thanks to Renato Athaydes for his job.<\/li>\n<li>Manage OSGi deployment through Gradle enhances the development process by automatization and isolation the execution from Eclipse<\/li>\n<\/ul>\n<\/div>\n<h2>10. Download the Eclipse Project<\/h2>\n<p>This was an example of Gradle OSGi Plugin.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/GradleOSGiProject.zip\"><strong>Gradle OSGi Project<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example&nbsp;we will talk about how to integrate OSGi frameworks with Gradle build&nbsp;tool. This work consists in build JAR files and customizing Manifest file through Gradle build Script and Deploying them in a OSGi Container like Apache Felix. 1. Introduction to Gradle and OSGi Integration Gradle is an automatic build tool of more use &hellip;<\/p>\n","protected":false},"author":37,"featured_media":20342,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[908],"tags":[],"class_list":["post-23646","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gradle"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Gradle OSGi Plugin Example: BNDTools Bundle Integration - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"This work consist in build OSGi bundles and customizing Manifest file through gradle OSGi plugin and Deploying them in a OSGi Container like Apache Felix\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Gradle OSGi Plugin Example: BNDTools Bundle Integration - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"This work consist in build OSGi bundles and customizing Manifest file through gradle OSGi plugin and Deploying them in a OSGi Container like Apache Felix\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-07-16T08:00:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-03T11:01:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andres Cespedes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@acespedes12\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andres Cespedes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/\"},\"author\":{\"name\":\"Andres Cespedes\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a32ee4d7e34cb21bfd2a5a68cf174f8a\"},\"headline\":\"Gradle OSGi Plugin Example: BNDTools Bundle Integration\",\"datePublished\":\"2015-07-16T08:00:35+00:00\",\"dateModified\":\"2019-04-03T11:01:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/\"},\"wordCount\":1241,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg\",\"articleSection\":[\"Gradle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/\",\"name\":\"Gradle OSGi Plugin Example: BNDTools Bundle Integration - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg\",\"datePublished\":\"2015-07-16T08:00:35+00:00\",\"dateModified\":\"2019-04-03T11:01:11+00:00\",\"description\":\"This work consist in build OSGi bundles and customizing Manifest file through gradle OSGi plugin and Deploying them in a OSGi Container like Apache Felix\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Gradle\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/gradle\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Gradle OSGi Plugin Example: BNDTools Bundle Integration\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a32ee4d7e34cb21bfd2a5a68cf174f8a\",\"name\":\"Andres Cespedes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Andres-Cespedes_avatar_1418741113-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Andres-Cespedes_avatar_1418741113-96x96.jpg\",\"caption\":\"Andres Cespedes\"},\"description\":\"Andres is a Java Software Craftsman from Medellin Colombia, who strongly develops on DevOps practices, RESTful Web Services, Continuous integration and delivery. Andres is working to improve software process and modernizing software culture on Colombia.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\",\"http:\/\/co.linkedin.com\/in\/andrespedes12\",\"https:\/\/x.com\/acespedes12\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/andres-cespedes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Gradle OSGi Plugin Example: BNDTools Bundle Integration - Java Code Geeks","description":"This work consist in build OSGi bundles and customizing Manifest file through gradle OSGi plugin and Deploying them in a OSGi Container like Apache Felix","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/","og_locale":"en_US","og_type":"article","og_title":"Gradle OSGi Plugin Example: BNDTools Bundle Integration - Java Code Geeks","og_description":"This work consist in build OSGi bundles and customizing Manifest file through gradle OSGi plugin and Deploying them in a OSGi Container like Apache Felix","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-07-16T08:00:35+00:00","article_modified_time":"2019-04-03T11:01:11+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg","type":"image\/jpeg"}],"author":"Andres Cespedes","twitter_card":"summary_large_image","twitter_creator":"@acespedes12","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Andres Cespedes","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/"},"author":{"name":"Andres Cespedes","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a32ee4d7e34cb21bfd2a5a68cf174f8a"},"headline":"Gradle OSGi Plugin Example: BNDTools Bundle Integration","datePublished":"2015-07-16T08:00:35+00:00","dateModified":"2019-04-03T11:01:11+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/"},"wordCount":1241,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg","articleSection":["Gradle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/","name":"Gradle OSGi Plugin Example: BNDTools Bundle Integration - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg","datePublished":"2015-07-16T08:00:35+00:00","dateModified":"2019-04-03T11:01:11+00:00","description":"This work consist in build OSGi bundles and customizing Manifest file through gradle OSGi plugin and Deploying them in a OSGi Container like Apache Felix","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/gradle-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/gradle\/gradle-osgi-plugin-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"Gradle","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/gradle\/"},{"@type":"ListItem","position":5,"name":"Gradle OSGi Plugin Example: BNDTools Bundle Integration"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a32ee4d7e34cb21bfd2a5a68cf174f8a","name":"Andres Cespedes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Andres-Cespedes_avatar_1418741113-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Andres-Cespedes_avatar_1418741113-96x96.jpg","caption":"Andres Cespedes"},"description":"Andres is a Java Software Craftsman from Medellin Colombia, who strongly develops on DevOps practices, RESTful Web Services, Continuous integration and delivery. Andres is working to improve software process and modernizing software culture on Colombia.","sameAs":["http:\/\/www.javacodegeeks.com\/","http:\/\/co.linkedin.com\/in\/andrespedes12","https:\/\/x.com\/acespedes12"],"url":"https:\/\/examples.javacodegeeks.com\/author\/andres-cespedes\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/23646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=23646"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/23646\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/20342"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=23646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=23646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=23646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}