Hi, we are having issues adding dependencies to a maven project that is based on the latest version of aem-project-archetype
To simplify the question I created a dummy project using the archetype.
After the project is created I run the
mvn clean install -U -PautoInstallPackage
maven command to install the package to my local AEM instance. So far so good.
Now for the purpose of the test I create a class that as a dependency on ehcache. I add the necessary dependency to pom.xml of the core module
<dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> <version>2.8.0</version> </dependency>
I run the mvn clean install and now the core bundle wont start and I get this message in the Imported Packages section of the bundle when looking at the felix console
net.sf.ehcache,version=[2.8,3) -- Cannot be resolved net.sf.ehcache.config,version=[2.8,3) -- Cannot be resolved
After looking at the felix maven-bundle-plugin documentation http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html
I see that I need to add the dependency through either <Embed-Dependency> or <Private-Package>. So trying this
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> <Embed-Dependency> ehcache;inline=true </Embed-Dependency> <Sling-Model-Packages> com.mvndt.core </Sling-Model-Packages> </instructions> </configuration> </plugin>
And running
mvn clean install -U -PautoInstallPackage
The bundle still won't start, but now I get multiple missing dependencies under the imported package section in the felix console
org.hibernate -- Cannot be resolved org.hibernate.cache -- Cannot be resolved org.hibernate.cache.access -- Cannot be resolved org.hibernate.cfg -- Cannot be resolved org.hibernate.impl -- Cannot be resolved org.hibernate.stat -- Cannot be resolved org.hibernate.transaction -- Cannot be resolved org.quartz -- Cannot be resolved org.quartz.impl -- Cannot be resolved org.quartz.impl.jdbcjobstore -- Cannot be resolved org.quartz.impl.matchers -- Cannot be resolved org.quartz.simpl -- Cannot be resolved org.terracotta.quartz -- Cannot be resolved org.terracotta.toolkit -- Cannot be resolved org.terracotta.toolkit.atomic -- Cannot be resolved org.terracotta.toolkit.builder -- Cannot be resolved org.terracotta.toolkit.cache -- Cannot be resolved org.terracotta.toolkit.cluster -- Cannot be resolved org.terracotta.toolkit.collections -- Cannot be resolved ...
It looks like my dependency is now conflicting with other dependency in the bundle.
Does anyone have any idea what I'm doing wrong here?
I dont get this problem with all dependencies but on some cases like with ehcache I do
Any help is more than welcome.
Thanks
-Alain
Solved! Go to Solution.
Views
Replies
Total Likes
Hey Alain,
You need to push it a bit by telling it does not need to import these:
Modify your maven bundle plugin instructions, tell it what you want to import via import configuration:
<Import-Package>
!javax.jms.*,!org.hibernate,!org.hibernate.cache,!org.hibernate.cache.access,!org.hibernate.cfg,!org.hibernate.impl,!org.hibernate.stat,!org.hibernate.transaction,!sun.misc,!sun.security.util, *
</Import-Package>
This way you would make your ehcache available. This makes base ehcache such as put, get and other essential features working correctly.
Thanks,
Peter
Views
Replies
Total Likes
Hi Alain. I will look into this mon
Views
Replies
Total Likes
The ehcache OSGI bundle is already available in the default AEM installation. It should work if you add the following dependency in the pom file of your bundle-
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.ehcache</artifactId>
<version>2.6.5_1</version>
</dependency>
Views
Replies
Total Likes
Thanks Kunal23
I will try this. Is there a better way to anticipate these issues when dealing with OSGI. Instead of finding out after you deployed it. Just for future references.
-Alain
Views
Replies
Total Likes
Hi Alain,
you need to add: <scope>provided</scope> to you dependancy, which means it will not need to be added to your bundle as AEM will provide the jar.
You can use the dependancy finder to determine if a class is already provided by AEM, "/system/console/depfinder".
Regards,
Opkar
Views
Replies
Total Likes
These messages:
org.hibernate -- Cannot be resolved
org.hibernate.cache -- Cannot be resolved
org.hibernate.cache.access -- Cannot be resolved
org.hibernate.cfg -- Cannot be resolved
org.hibernate.impl -- Cannot be resolved
org.hibernate.stat -- Cannot be resolved
org.hibernate.transaction
mean that you are trying to use these Java packages from within AEM. However - there are no OSGi bundles in AEM that exports these packages. You need to get JAR files that contain these Java packages into an OSGi bundle and deploy. You can use an eclipse plug-in project to wrap them into an OSGi bundle. See this artilce and notice how we wrap the simple JSON jar into an OSGi bundle:
https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html
Views
Replies
Total Likes
Thanks Opkar,
Replacing my ehcache dependency with this one
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.ehcache</artifactId>
<version>2.6.5_1</version>
<scope>provided</scope>
</dependency>
And adding it to my maven-bundle-plugin config like this
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>
commons-lang,
org.apache.servicemix.bundles.ehcache
</Embed-Dependency>
<Sling-Model-Packages>
com.mvndt.core
</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>
The bundle still wont start and I still get these errors in the Felix console when looking at the bundle description.
Imported Packages com.mvndt.core.models from mvnDependencyTest.mvndt.core (546)
com.mvndt.core.services.cache from mvnDependencyTest.mvndt.core (546)
javax.annotation from org.apache.felix.framework (0)
javax.inject,version=[0.0,1) from org.apache.sling.models.api (344)
javax.jcr,version=[2.0,3) from org.apache.sling.jcr.jcr-wrapper (106)
javax.jms -- Cannot be resolved
javax.management from org.apache.felix.framework (0)
javax.management.openmbean from org.apache.felix.framework (0)
javax.naming from org.apache.felix.framework (0)
javax.servlet from org.apache.felix.http.servlet-api (29)
javax.transaction from org.apache.aries.transaction.manager (18)
javax.transaction.xa from org.apache.aries.transaction.manager (18)
javax.xml.parsers from org.apache.felix.framework (0)
org.apache.log4j,version=[1.2,2) from log4j.over.slf4j (3)
org.apache.sling.api,version=[2.3,3) from org.apache.sling.api (184)
org.apache.sling.api.request,version=[2.4,3) from org.apache.sling.api (184)
org.apache.sling.api.resource,version=[2.5,3) from org.apache.sling.api (184)
org.apache.sling.api.servlets,version=[2.1,3) from org.apache.sling.api (184)
org.apache.sling.commons.osgi,version=[2.2,3) from org.apache.sling.commons.osgi (56)
org.apache.sling.models.annotations,version=[1.0,2) from org.apache.sling.models.api (344)
org.apache.sling.settings,version=[1.3,2) from org.apache.sling.settings (13)
org.hibernate -- Cannot be resolved
org.hibernate.cache -- Cannot be resolved
org.hibernate.cache.access -- Cannot be resolved
org.hibernate.cfg -- Cannot be resolved
org.hibernate.impl -- Cannot be resolved
org.hibernate.stat -- Cannot be resolved
org.hibernate.transaction -- Cannot be resolved
org.osgi.framework,version=[1.5,2) from org.apache.felix.framework (0)
org.osgi.service.component,version=[1.1,2) from org.apache.felix.scr (55)
org.osgi.service.event,version=[1.2,2) from org.apache.felix.eventadmin (51)
org.slf4j,version=[1.5,2) from slf4j.api (14)
org.xml.sax from org.apache.felix.framework (0)
org.xml.sax.helpers from org.apache.felix.framework (0)
sun.misc -- Cannot be resolved and overwritten by Boot Delegation
Any ideas?
-Alain
Views
Replies
Total Likes
Hey Alain,
You need to push it a bit by telling it does not need to import these:
Modify your maven bundle plugin instructions, tell it what you want to import via import configuration:
<Import-Package>
!javax.jms.*,!org.hibernate,!org.hibernate.cache,!org.hibernate.cache.access,!org.hibernate.cfg,!org.hibernate.impl,!org.hibernate.stat,!org.hibernate.transaction,!sun.misc,!sun.security.util, *
</Import-Package>
This way you would make your ehcache available. This makes base ehcache such as put, get and other essential features working correctly.
Thanks,
Peter
Views
Replies
Total Likes
Thanks Scott and Peter for the answer.
Peter that did it. The bundle now start without any issues.
For my understanding, it's org.apache.servicemix.bundles.ehcache that is adding the additional dependencies on org.hibernate, javax.jms and sun.misc?
And by using
<Import-Package> !javax.jms.*,!org.hibernate,!org.hibernate.cache,!org.hibernate.cache.access,!org.hibernate.cfg,!org.hibernate.impl,!org.hibernate.stat,!org.hibernate.transaction,!sun.misc,!sun.security.util, * </Import-Package>
I'm supressing these dependencies?
-Alain
Views
Replies
Total Likes
Yes - by commenting them out in the Import section - you are telling AEM that these Java packages are not needed. But if your bundle works, then you are good.
Views
Replies
Total Likes