<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>How to use OSGI Embed-Dependency for common 3rd party JAR-s</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=111041966" />
  <subtitle>How to use OSGI Embed-Dependency for common 3rd party JAR-s</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=111041966</id>
  <updated>2026-04-04T22:15:59Z</updated>
  <dc:date>2026-04-04T22:15:59Z</dc:date>
  <entry>
    <title>RE: How to use OSGI Embed-Dependency for common 3rd party JAR-s</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111045992" />
    <author>
      <name>Kyle Joseph Stiemann</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111045992</id>
    <updated>2018-09-26T18:55:47Z</updated>
    <published>2018-09-26T18:55:47Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Hi Peter,&lt;br&gt; Technically this approach could work, but you’re
  going to run into some difficult issues. We might not be able to help
  with your specific approach, but…we’re actually planning on &lt;a href="https://issues.liferay.com/browse/FACES-3024"&gt;making the
    Liferay Faces jars into OSGi bundles&lt;/a&gt; so they can be deployed to &lt;strong&gt;
    &lt;code&gt;$LIFERAY_HOME/osgi/modules&lt;/code&gt;&lt;/strong&gt; (instead of
  including them in each WAR's &lt;strong&gt;
    &lt;code&gt;WEB-INF/lib&lt;/code&gt;&lt;/strong&gt; folder). If you’re feeling
  adventurous, you could build the branches listed my latest comment in
    &lt;a href="https://issues.liferay.com/browse/FACES-3024"&gt;FACES-3024&lt;/a&gt;
  from source and try it out. Also, even with everything (mostly)
  working, we still had to include the RichFaces jar in the WAR's &lt;strong&gt;
    &lt;code&gt;WEB-INF/lib&lt;/code&gt;&lt;/strong&gt; folder since it is not an OSGi
  bundle. If you decide that you still want to create a common OSGi jar,
  there’s no guarantee that we can support you, but you can take a look
  at FACES-3024 and the linked github branches for information about how
  we dealt with JSF/OSGi incompatibilities.&lt;/p&gt;
&lt;p&gt;- Kyle&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Kyle Joseph Stiemann</dc:creator>
    <dc:date>2018-09-26T18:55:47Z</dc:date>
  </entry>
  <entry>
    <title>Moved to the Liferay Faces - English category.</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111045964" />
    <author>
      <name>Kyle Joseph Stiemann</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111045964</id>
    <updated>2018-09-26T18:31:10Z</updated>
    <published>2018-09-26T18:31:10Z</published>
    <summary type="html">Moved to the Liferay Faces - English category.</summary>
    <dc:creator>Kyle Joseph Stiemann</dc:creator>
    <dc:date>2018-09-26T18:31:10Z</dc:date>
  </entry>
  <entry>
    <title>How to use OSGI Embed-Dependency for common 3rd party JAR-s</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111041965" />
    <author>
      <name>Péter Jaloveczki</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111041965</id>
    <updated>2018-09-26T12:05:34Z</updated>
    <published>2018-09-26T12:05:34Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;I have a Liferay system with several portlets. Most of these portlets
  have redundant JSF related JAR-s in them so I would like to remove the
  redundancy, and create an OSGI bundle for the commonly used JAR-s.&lt;/p&gt;
&lt;p&gt;The idea would be that all of my portlets would use this common
  bundle as a dependency.&lt;/p&gt;
&lt;p&gt;After some reading about I ended up with something similar in my
  maven pom:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;&amp;amp;lt;plugin&amp;amp;gt;
            &amp;amp;lt;groupId&amp;amp;gt;org.apache.felix&amp;amp;lt;/groupId&amp;amp;gt;
            &amp;amp;lt;artifactId&amp;amp;gt;maven-bundle-plugin&amp;amp;lt;/artifactId&amp;amp;gt;
            &amp;amp;lt;version&amp;amp;gt;2.3.4&amp;amp;lt;/version&amp;amp;gt;
            &amp;amp;lt;extensions&amp;amp;gt;true&amp;amp;lt;/extensions&amp;amp;gt;
            &amp;amp;lt;configuration&amp;amp;gt;
                &amp;amp;lt;remoteOBR&amp;amp;gt;true&amp;amp;lt;/remoteOBR&amp;amp;gt;
                &amp;amp;lt;instructions&amp;amp;gt;
                    &amp;amp;lt;Bundle-SymbolicName&amp;amp;gt;${project.artifactId}&amp;amp;lt;/Bundle-SymbolicName&amp;amp;gt;
                    &amp;amp;lt;Bundle-Name&amp;amp;gt;${project.name}&amp;amp;lt;/Bundle-Name&amp;amp;gt;
                    &amp;amp;lt;Bundle-Vendor&amp;amp;gt;${project.organization.name}&amp;amp;lt;/Bundle-Vendor&amp;amp;gt;
                    &amp;amp;lt;Import-Package&amp;amp;gt;
                        !sun.reflect,......,*
                    &amp;amp;lt;/Import-Package&amp;amp;gt;
                    &amp;amp;lt;Embed-Dependency&amp;amp;gt;*;scope=compile|runtime&amp;amp;lt;/Embed-Dependency&amp;amp;gt;
                    &amp;amp;lt;Embed-Transitive&amp;amp;gt;true&amp;amp;lt;/Embed-Transitive&amp;amp;gt;
                &amp;amp;lt;/instructions&amp;amp;gt;
            &amp;amp;lt;/configuration&amp;amp;gt;
        &amp;amp;lt;/plugin&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And I ended up with the following bundle jar:&lt;/p&gt;
&lt;p&gt;My Manifest:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;Manifest-Version: 1.0
Bundle-SymbolicName: my-common-bundle
Built-By: pjaloveczki
Bundle-ManifestVersion: 2
Bnd-LastModified: 1537882770915
Embed-Dependency: *;scope=compile|runtime
Import-Package: com.liferay.portal.kernel.exception,com.liferay.portal
 .kernel.language,com.liferay.portal.kernel.model,......,org.w3c.dom.styleshe
 ets,sun.misc
Tool: Bnd-1.15.0
Bundle-Name: my-common-bundle
Bundle-Version: 1.0.0
Bundle-ClassPath: .,sac-1.3.jar,...all..my..dependecies...,com.liferay.faces.bridge.api-4.1.0.jar
Ignore-Package: net.sf.cglib.proxy,..all..ignored..packages...javax.ejb
Embed-Transitive: true
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.8.0_171&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Content:&lt;/p&gt;
&lt;p&gt;
  &lt;a href="https://i.stack.imgur.com/oVR88.jpg"&gt;&lt;img alt="enter image description here" src="https://i.stack.imgur.com/oVR88.jpg"&gt;&lt;/a&gt;From what I can see,
  this is exactly what I needed, at least this is how I pictured it.&lt;/p&gt;
&lt;p&gt;In my consuming portlet I added the following to my manifest:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;Require-Bundle: my-common-bundle;bundle-version="1.0.0"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I figured something like this should work, however I am obviously
  wrong as when I try to deploy my portlet one of the classes is not
  being found provided by the common bundle:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;java.lang.ClassNotFoundException: org.richfaces.webapp.ResourceServlet cannot be found by MyPortlet&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;On the other hand if I add the following to my common bundle:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;&amp;amp;lt;Export-Package&amp;amp;gt;org.richfaces.webapp&amp;amp;lt;/Export-Package&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The class is found, but I am ended up with this:&lt;/p&gt;
&lt;p&gt;
  &lt;a href="https://i.stack.imgur.com/QxV1M.jpg"&gt;&lt;img alt="enter image description here" src="https://i.stack.imgur.com/QxV1M.jpg"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So essentially I have the class twice once in the JAR and once
  flattened out, even though it's kind of starting to work.&lt;/p&gt;
&lt;p&gt;There are several reason I don't like this approach:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;I would prefer using structured jars because I consider it cleaner&lt;/li&gt;
  &lt;li&gt;Most of these jars contain configuration files that could overlap
    if I flatten everything out&lt;/li&gt;
  &lt;li&gt;There must be a way to use embedded jars properly since otherwise
    this feature would not exist&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Can anyone help, what it the proper way to use these embedded jars in
  an OSGI without having to flatten them out?&lt;/p&gt;
&lt;p&gt;Thank! Peter&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;EDIT:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It seems that classes are being deployed fine and are resolved after
  I've added&lt;/p&gt;
&lt;p&gt;
  &lt;code&gt;&amp;amp;lt;_exportcontents&amp;amp;gt;!org.apache.commons.logging,*&amp;amp;lt;/_exportcontents&amp;amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;however I am getting different types of errors which I am not getting
  when I put my JARs in my portlets.&lt;/p&gt;
&lt;p&gt;Previously I was getting ClassNotFoundErrors and such, now I am getting:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;java.lang.NullPointerException
    at javax.faces.CurrentThreadToServletContext.getFallbackFactory(CurrentThreadToServletContext.java:79)
    at javax.faces.FactoryFinderInstance.getFactory(FactoryFinderInstance.java:551)
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:283)
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:358)


java.lang.NullPointerException
        at javax.portlet.faces.GenericFacesPortlet.getBridgeClassName(GenericFacesPortlet.java:193)
        at javax.portlet.faces.GenericFacesPortlet.getBridge(GenericFacesPortlet.java:762)
        at javax.portlet.faces.GenericFacesPortlet.init(GenericFacesPortlet.java:448)
        at com.liferay.portlet.InvokerPortletImpl.init(InvokerPortletImpl.java:297)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It seems to me classes are loaded, but the JAR manifests are not
  being processed or something similar. Any ideas?&lt;/p&gt;
&lt;p&gt;I have to reiterate, that if I cope same jars in the bundle in my&amp;nbsp;
  portlet everything works fine.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Péter Jaloveczki</dc:creator>
    <dc:date>2018-09-26T12:05:34Z</dc:date>
  </entry>
</feed>
