Menu

Showing posts with label OSGi. Show all posts
Showing posts with label OSGi. Show all posts

Service-Component entry can not be located in JAR: OSGI-INF

We might come to this issue while building the AEM code. The issue is with the @compoennt properties or the definition given for the file. In most of the cases error "Service-Component entry can not be located in JAR: OSGI-INF" says, that the @component name property which we are trying to give here is a duplicate and that name has been already given to a class, hence this name can not be accepted for a new component because it causes the unnecessary conflict between two components, and difficult to generate the meta-type or metadata, and manage the OSGi component.


[ERROR] Bundle com.rashid.aem.bundles:servlets:bundle:1.0.0-SNAPSHOT : Service-Component entry can not be located in JAR: OSGI-INF/com.rashid.aem.servlets.MobileAppImageServlet.xml~

[ERROR] Error(s) found in bundle configuration


Resolution

Update the name property value under @component annotation.


Example:

@Component( immediate = true,
service = Servlet.
class,
name =
"com.rashid.aem.servlets.GetAllImageServlet",
property = {
"sling.servlet.selectors=mobileapp",
"sling.servlet.extensions=json",
"sling.servlet.methods=GET",
"sling.servlet.paths=/bin/getAllImages"})

AEM service unsatisfied

When you see your AEM service and servlet is showing in state unsatisfied. Then click on the class name and see the detail, on the OSGi console that what causing this issue and which reference is unsatisfied.

Unsatisfied
Service Name: org.apache.sling.api.resource.ResourceResolver
Cardinality: 1..1
Policy: static
Policy Option: reluctant
No Services bound


ResourceResolver is not satisfied or the way of creating ResourceResolver object is not correct.


Policy Option

RELUCTANT
          The reluctant policy option is the default policy option for both static and dynamic reference policies.


References

1. Reference Policy Option

sun.misc - cannot be resolved | AEM Bundle

sun.misc -- Cannot be resolved but is not required and overwritten by Boot Delegation

Resolution

This error we see sometimes while installing bundle in Adobe Experience Manager(AEM). If you are seeing this error just after the installation of the package then wait for a few minutes to resolve the dependencies. Most of the time it will resolve automatically as soon as the dependent library or service will available. After a few minutes if this is not getting resolved then check your POM and ensure you are adding the correct dependency which is available in the system.

How to create an OSGi fragment project?

Hello readers, today we are going to explain how to create an OSGi fragment project using Eclipse IDE.

The first step to create OSGi fragment is to understand the need of the OSGi fragment and select a host bundle using which this OSGi fragment is going to access and resolved within your application. To understand the OSGi fragment please go through by our previous OSGi fragment posts.

Once we have the clear picture about fragment and you have opted the host bundle to register the fragment then, follow the below steps to create OSGi fragment project. For example we have a sample OSGi bundle with name "OSGitestBundle" and for this bundle we will create an OSGi fragment which helps this bundle to work as an extension of host bundle and provide additional information to host bundle. 

Step 1: Go to File >> New >> Other >> Plug-in Development >> Fragment Project and then click on the next button. 

Select OSGi fragment project from other project section in Eclipse
Select OSGi fragment project from other project section in Eclipse

Step 2: Now put a valid name OSGi fragment name in Project name text-box, and click on the next button. for example we have given project  name OSGiFragment

OSGI fragment project name
OSGi fragment project name


Step 3: In this step you will see, few fields are auto filled with the name of your OSGi fragment project, as you have given the project name in the previous step. In this step you have to add the plug-in ID information or host name information of this fragment, so this get merge with host bundle. here we will put the project name OSGitestBundle and then click on the finish button.

Plug in or host name information OSGi fragment
Plug in or host name information OSGi fragment

Step 4: Now open the project explorer in your Eclipse and open the manifest file "MANIFEST.MF" at location [Fragment-PROJECT-NAME] >> META-INF >> MANIFEST.MF
Manifest file stored at directory
Manifest file location


In manifest file you will see the following entries:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: OSGiFragmen
Bundle-SymbolicName: OSGiFragmen
Bundle-Version: 1.0.0.qualifier
Fragment-Host: OSGitestBundle
Automatic-Module-Name: OSGiFragment
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

Here Fragment-Host will hold the host bundle name.

OSGi fragment bundle

What is OSGi fragment?

OSGi fragment is the java archive file or jar file or bundle, which have some classes, resource and header. The purpose of fragment to develop an extension of a bundle, which add on additional functionality and merge those functionality with host bundle at the time of host bundle is getting resolve. Before host bundle get resolved fragment appended to host. Following are the key points which we need to keep in mind while working with OSGi fragment.


  • Fragment is treated as part of the host bundles. 
  • A fragment cannot have its own class loader or bundle activator. 
  • Fragment bundle cannot override the information present in the host bundles. 
  • Both host and fragment share the same class loader from host bundle. 
  • An OSGi fragment doesn't have it life-cycle and that means we can't activate, start, stop a fragment. 
  • All classes and definition of fragment are merged with host definition when the host bundle get resolved. If the fragment dependencies cannot be resolved, the fragment does not attach to the host bundle. 
  • If any information from host and fragment conflicts then fragment will not attach and merge with host bundle. 
  • Fragments extend host bundles with resources, classes, and permitted headers. 
  • Fragments can only add new files, and does not replace or override existing files from host. 
  • OSGi fragment JAR file contains manifest file which have host bundle information. 
  • Fragment jar cannot be use independently. 
  • Fragments bundles could you attached with one or many host bundles. 


Why do we have fragments and what is the role of fragments and why we use? 


  • To provide the extra classes or additional functionality to host bundle. 
  • Add configuration files and properties.

You can create a fragment project using eclipse.

To create an OSGi fragment project in Eclipse follow the below steps:
  1. Go to File >> New >> Other >> Plug-in Development >> Fragment Project
  2. Select Fragment project and click on the next.
  3. Put a valid project name for your fragment and then click on next button.
  4. Now under the Host plun-in section, put the host bundle name in plug-in ID field.

Here is the complete step by step guide to create an OSGi fragment project using Eclipse. >> https://rashidjorvee.blogspot.com/2019/03/how-to-create-osgi-fragment-project.html