Expand my Community achievements bar.

SOLVED

How to use external jar in Adobe CQ5?

Avatar

Former Community Member

Hi,

 I want to use some classes from external jar in CQ5.How its possible to do.

 Please suggest me a solution.

 

Thanks in advance

Sridhar.M

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Well there are a few things to keep in mind :-

1. The packages you need may already be exported by an existing OSGI bundle provided as part of the AEM run-time. Use the Web Console dependency finder and search for the package names you need.

2. You should be using a Maven project (ideally created from one of the available archetypes such as the multi-module archetype from the Adobe repo or CQBlueprints). That will give your project a suitable structure and from there you just need to add the dependencies that you need in the normal way. For AEM provided packages the dependency finder will provide you with the correct POM entry. For external JARs just search Maven Central, it has pretty much all that you are likely to need.

3. For packages (from third party libraries - Jars), if you need them at run-time, you need to create an OSGI bundle and deploy that to AEM. Make sure you export all of the packages that you need to bind to in your calling code. You can use the Maven bundle plug-in to create the bundle for you and ensure that the correct manifest is constructed. There are some good articles around that show you how to do this step-by-step (google is your friend), if I get a moment later I'll post a couple of links.

HTHs

Fraser.

View solution in original post

7 Replies

Avatar

Correct answer by
Former Community Member

Well there are a few things to keep in mind :-

1. The packages you need may already be exported by an existing OSGI bundle provided as part of the AEM run-time. Use the Web Console dependency finder and search for the package names you need.

2. You should be using a Maven project (ideally created from one of the available archetypes such as the multi-module archetype from the Adobe repo or CQBlueprints). That will give your project a suitable structure and from there you just need to add the dependencies that you need in the normal way. For AEM provided packages the dependency finder will provide you with the correct POM entry. For external JARs just search Maven Central, it has pretty much all that you are likely to need.

3. For packages (from third party libraries - Jars), if you need them at run-time, you need to create an OSGI bundle and deploy that to AEM. Make sure you export all of the packages that you need to bind to in your calling code. You can use the Maven bundle plug-in to create the bundle for you and ensure that the correct manifest is constructed. There are some good articles around that show you how to do this step-by-step (google is your friend), if I get a moment later I'll post a couple of links.

HTHs

Fraser.

Avatar

Former Community Member

Oh, and in addition to option (3), you *can* embed external JARs in your application bundle (including transitive dependencies if necessary) using the Import-Packages/Embed-Transitives (check the exact spelling) directives. Sometimes that's easier than creating separate OSGI bundles for 3rd party JARs, but you need to balance whether you are likely to want to reuse those JARs across multiple applications as well as considering the level of isolation you need (ie. anything that is shared always has a greater 'ripple' effect when you change it).

HTHs

Fraser.

Avatar

Former Community Member

Thanks man.

Could u tell me the steps to achieve this?

Avatar

Former Community Member

For (1), you would typically use : http://<server>:<port>/system/console/depfinder (i.e. http://localhost:4502/system/console/depfinder if you are running AEM locally).

For the rest, it really depends how much experience you have already with Maven and OSGI ??  Do you use Maven for AEM development already ?

Fraser.

Avatar

Former Community Member

Fraser Goffin wrote...

For (1), you would typically use : http://<server>:<port>/system/console/depfinder (i.e. http://localhost:4502/system/console/depfinder if you are running AEM locally).

For the rest, it really depends how much experience you have already with Maven and OSGI ??  Do you use Maven for AEM development already ?

Fraser.

 


CRX is not locally installed here.

No,I didn't tried maven with AEM.

I want to work with jars directly not dependencies.

Thanks

Avatar

Former Community Member

> CRX is not locally installed here

That doesn't matter too much as long as you are able to connect to your author instance. Most times you'll be using HTTP (rather than webdva or other options). Personally I find it a *lot* easier to have a local install, but it is resource hungry. Anyway, this shouldn't be a major restriction to your work.

> No,I didn't tried maven with AEM.

I would *strongly* suggest that you look into using Maven. Its a *lot* easier to manage your JAR dependencies, there are pre-built archetypes (project templates which provide appropriate structure specifically for AEM), highly useful 'plug-ins' that support compilation, unit testing, the creation of OSGI bundles that you will need for AEM, and the auto-deployment of both bundles and packages into the JCR.

Pretty indispensible I would say, and well worth the investment in your time (the learning curve is pretty small at least for the basics).

> I want to work with jars directly not dependencies.

Using Maven you *are* directly using JARs its just that it provides a much easier way of controlling which ones (versions) are used and helps enormously with things like 'transitive dependencies' (when a JAR that you are using directly requires other JARs, some of which require other JARs, and so on - hard to do by yourself). As far as making third party JARs that you need for your application logic available in the AEM run-time (i.e. NOT provided with the product itself), you either need to embed them in your project bundles (Maven will help you with that - see earlier in this thread) or create separate bundles which export the packages that you require (Maven very helpful again).

Fraser.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----