OSGi Package Status Inactive (CQ5 Maven Project) WHY?

I know that when the status of a package is set to CQ, there are dependencies, so the package cannot be "active".

I use the Jersey client v 2.17 in the CQ5 service, so I need an ATM for Jersey clients. I added a dependency in /bundle/pom.xml . My package successfully compiles and deploys BUT NEVER INCLUDES ACTIVE

I manually added the Jersey client jar in the Felix console, after doing this, my package was activated, but the Jersey client gang is not active , so I continue to receive ClassNotFoundError , since there are also transitive dependencies in the Jersey Client bank.

I tried the following:

  • Manually tried to resolve the dependencies by adding Jars to the Felix console. I failed . Loop never ends (Transitive Dependencies)
  • I tried some kind of tweak by changing the Jarcenter Core Jar manifest , adding DynamicImport-Package: * . This circumvents the OSAi conatainer that at runtime it will find Jars. This worked for me in the past, but now it needs some classes that aren't there. (Both the Jars the Jersey Client and My Bundle become active, BUT I get a class NOT found Error, because the classes are not really there no matter how much I try to trick OSait Conatainer) Failure .
  • So I tried another, I added all the dependent Jars to /bundle/pom.xml . Since I am using Maven, I thought this would solve the problem, but my package is still Installed NOT Active

My third step was an unsuccessful failure. What good is Maven doing for you when you install all the Jars MANUALLY in the Felix console anyway ?!

What should I do?

+1
source share
3 answers

First of all, Maven only helps you with build-time dependencies, and Maven dependencies are at the jar level. When installing packages in an OSGi container, you have to deal with run-time dependencies that are at the package level.

Thus, there is a mismatch between build time and runtime, since dependencies work differently. You can argue that Maven is not so good, and so at least some people who run many OSGi applications have switched to Bnd / Bndtools and the Gradle build command line.

Get back to your problem. You execute the missing dependencies at runtime. Your package imports packages that are not exported by any packages. To fix this, you can use one of two strategies:

  • You can embed all the dependencies that you need in your package. Effectively here you will need to embed the Jersey client (and in transit all the dependencies that it needs). You could not expose any of them in other packages, all code will appear in your package.
  • You can install all the dependencies you need as packages. This means that you need to transit find all the packages that you need to run the Jersey Client. There are some tools to help you with this. Maven is not one of them.

Hope this helps. Perhaps this is not what you hoped to hear.

+1
source

@Marcel Offermans answer is correct, you must install all the dependencies that your package should run, if there are too many of them, you do not manage them properly. How easy it is to deploy them, CQ5 has a good way to do this.

In CQ5, you usually install applications through packages that are nothing but a zip file that contains both the content to be copied to the JCR repository and any Java package that your application may need.

You may have noticed that, as a rule, in CQ5 applications you have 2 maven modules, (tip: use their maven archetypes to create your projects) for content and one for java code (there can be more than one or none). What happens when creating a content package is that any package that uses the same group identifier is automatically embedded in the package, but you use any package that is not already installed, you must configure it so that it is embedded .

This sample configuration is taken from the documentation. It should give you an idea of ​​how to add any dependency you need to deploy to the OSGi container along with your application:

  <plugin> <groupId>com.day.jcr.vault</groupId> <artifactId>content-package-maven-plugin</artifactId> <version>0.0.20</version> <extensions>true</extensions> <configuration> <filters> <filter> <root>/apps/myapp</root> </filter> </filters> <embeddeds> <embedded> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.jcr.jackrabbit.usermanager</artifactId> <target>/apps/myproject/install</target> </embedded> </embeddeds> </configuration> </plugin> 

as a final tip, use the OSGi dependency search in http://localhost:4502/system/console/depfinder to find any dependency you might need. It may already be installed in your instance if you do not notice.

If you want to embed the jar inside the package so that it is not open, you can do it with the maven-bundle-plugin (I assume you use it since it is the standard for AEM development) using the Embed-Dependency command:

 <Embed-Dependency>artifactId</Embed-Dependency> 

See the documentation for more information on how to use this command.

+1
source

I solved it. Both @Marcel Offermans and @santiagozky you are right in your own way. But there is something that I learned from my experience, I would like to share.

1) MAVEN Bundle Plugin - This Maven profile Helps to load all your dependencies (including transitional ones to the last level), converts them automatically to OSGi format and places them in the target folder. they can be downloaded directly to the OSGi Console. Follow this link

Note. Just use bundleall instead of wrap to see my pom entry

 <!-- My Profile to Resolve Tansitive Dependencies --> <profile> <id>create-osgi-bundles-from-dependencies</id> <build> <plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.0.1</version> <extensions>true</extensions> <executions> <execution> <id>wrap-my-dependency</id> <goals> <goal>bundleall</goal> </goals> <configuration> <wrapImportPackage>;</wrapImportPackage> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> <!-- transitive dependenceis ENds --> 

Use command: mvn -Pcreate-osgi-bundles-from-dependencies bundle:bundleall

2) The Mentiond by @santiagozky method puts the package in the installation folder , but this is not in OSGi FORMAT , so the package does not start. Any inputs on this @santiagozky?

0
source

All Articles