Embedding third party jar into bundle | Community
Skip to main content
varuns46785756
Level 5
February 15, 2017
Question

Embedding third party jar into bundle

  • February 15, 2017
  • 3 replies
  • 4088 views

Hi,

I am using one servlet with import or reference to one API in the jar.I have added jar file as external jar in my eclipse but I am getting build error.

"package com.mypackage.api.config does not exist"

Please suggest how to add jar dependency in my servlet

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

varuns46785756
Level 5
February 15, 2017

Hi ,

I got the answer for my query, added dependency in my pom.xml and created one lib folder and added my jar file in it.

<dependency>

         <groupId>mycore-6.2</groupId>

         <artifactId>mycore-6.2</artifactId>

         <scope>system</scope>

         <version>1.0</version>

         <systemPath>${basedir}\src\lib\mycore-6.2.jar</systemPath>

       </dependency>

smacdonald2008
Level 10
February 15, 2017

Another way is to wrap the 3rd pary JAR into an OSGi bundle and deploy.  You can use Eclipse plug-in project for that purpose. 

See how we handle Simple JSON JAR in this community article/video: 

http://scottsdigitalcommunity.blogspot.ca/2013/06/posting-form-data-to-adobe-cq-using.html

smacdonald2008
Level 10
February 15, 2017

Ok - i think you mean when the 3rd party JAR is custom and not in the Maven repository. In that case...

You can place the JAR in your local Maven Repository and then reference it in your POM file. For example, to resolve myCustomJAR_1.0.0.jar within an AEM service, the myCustomJAR_1.0.0.jar file must be located in the Maven repository. You can upload the myCustomJAR_1.0.0.jar to Maven by using this Maven command: 

mvn install:install-file -Dfile=C:/plugins/myCustomJAR_1.0.0.jar -DgroupId=com.foo.reports -DartifactId=jrurbersrt1.0 -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true

Notice that you must specify the location of the myCustomJAR file in the -Dfile argument. Also notice that you specify the Dgroup and DartifactID values. Once you upload the JAR to Maven using this command, you can reference this JAR file using this Dependency.

<groupId>com.foo.reports</groupId>
<artifactId>jrurbersrt1.0</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>C:\Users\scottm\.m2\repository\com\foo\reports\jrurbersrt1.0\1.0\myCustomJAR_1.0.0.jar</systemPath>
</dependency>

Notice that scope element is system and systemPath references the location of the JAR file in the repository. (This dependency is used later in this article to build the AEM service)