Expand my Community achievements bar.

Something wrong with <Private-Package>or <Import-Package> when trying to add PDFBox

Avatar

Level 7

hi folks,

I can’t use itextpdf anymore for license reasons, so I’ve been trying to integrate PDFBox in my AEM project (AMS, 6.5)

 

I found this project with suggestions on how to do this:

 

https://github.com/ahmed-musallam/pdfbox-osgi-bundle

 

I added the maven-bundle-plugin updates below to my AEM “Java” module. It builds fine and my AEM project shows Active in the console. The PDF tests work ok during compile.

 

However I did notice that some of my Servlets and all of my custom Services are “Satisfied” but not Active.

These services don’t work in my Application.

Any ideas what might be wrong?

 

I didn't have <Private-Package> and <Import-Package> in my maven-bundle-plugin instructions before so I am assuming that it is something there that is wrong..... (it is like it is making my  *Impl* classes unavailable..)

 

Thanks

Fiona

 

Log errors

 

Servlet

 

*ERROR* [FelixDispatchQueue] org.apache.sling.servlets.resolver FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service factory returned null. (Component: com.xxx.servlets.xxxxx (1234)))

error.log:org.osgi.framework.ServiceException: Service factory returned null. (Component: com.xxx.servlets.xxxxx (1234))

 

Service ( called by Servlet)

DDA.log:org.osgi.framework.ServiceException: Service factory exception: Could not load implementation object class com.xxx.services.impl.SomethingServiceImpl

DDA.log:Caused by: java.lang.IllegalStateException: Could not load implementation object class com.xxx.services.impl.SomethingServiceImpl

stderr.log:ERROR : bundle com.xxx.xxx:1.0.0.SNAPSHOT (111)[com.xxx.services.impl.SomethingServiceImpl(123)] : Could not load implementation object class com.xxx.services.impl.SomethingServiceImp

 

 

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version> 4.2.1</version>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <Private-Package>org.bouncycastle.*</Private-Package>
            <Import-Package>
                sun.java2d.cmm;resolution:=optional,
                sun.java2d.cmm.*;resolution:=optional,
                *
            </Import-Package>
            <Embed-Dependency>
                pdfbox,
                fontbox
            </Embed-Dependency>
        </instructions>
    </configuration>
</plugin>

:


<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox -->
<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>pdfbox</artifactId>
    <version>2.0.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/fontbox -->
<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>fontbox</artifactId>
    <version>2.0.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bcprov-jdk15on</artifactId>
    <version>1.62</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on -->
<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bcpkix-jdk15on</artifactId>
    <version>1.62</version>
</dependency>

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

4 Replies

Avatar

Community Advisor

Hi @fionas76543059 Did you try with just the pdf box dependency in pom?

 

<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.20</version>
</dependency>
 
Just with that I am not seeing similar issue for existing bundles

Avatar

Community Advisor

Hello @fionas76543059,

 

The status satisfied is good enough for your OSGi component (servlet in this case) to be up and running. The issue that you are facing suggests that some dependencies (injected within the service) are not getting resolved. Do you see any error in the /system/console for this bundle?

Thanks   

Avatar

Level 7

If I just put in a pom entry for pdfbox, my bundle doesn't go Active as they are unresolved.

 

I tried using the project mentioned above to see if I could create a bundle with pdfbox package available.

 

I can install it in AEM and the bundle goes Active but the Export-Package just shows "---".

 

 I don't understand this.

Avatar

Level 7

ACtually it works o.k. when I explicitly add Export-Package. Now this bundle goes Active and my app goes App and seems to work o.k.

<instructions>
<Export-Package>org.apache.pdfbox;version=2.0.16,org.apache.pdfbox.pdmodel;version=2.0.16,org.apache.pdfbox.pdmodel.font;version=2.0.16,org.apache.pdfbox.pdmodel.graphics.image;version=2.0.16</Export-Package>
<Private-Package>org.bouncycastle.*</Private-Package>
<Import-Package>
sun.java2d.cmm;resolution:=optional,
sun.java2d.cmm.*;resolution:=optional,
*
</Import-Package>
<Embed-Dependency>
pdfbox,
fontbox
</Embed-Dependency>
</instructions>
</configuration>