I am trying to convert an .docx file to html using apache POI. Now the case is when I deploy my bundle to OSGi felix in CQ5 I am getting the exception as :
java.lang.NoClassDefFoundError: org/openxmlformats/schemas/wordprocessingml/x2006/main/impl/CTSectPrImpl$1HeaderReferenceList at org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.CTSectPrImpl.getHeaderReferenceList(Unknown Source) at org.apache.poi.xwpf.converter.core.MasterPageManager.visitHeadersFooters(MasterPageManager.java:200) at org.apache.poi.xwpf.converter.core.MasterPageManager.addSection(MasterPageManager.java:178) at org.apache.poi.xwpf.converter.core.MasterPageManager.compute(MasterPageManager.java:125) at org.apache.poi.xwpf.converter.core.MasterPageManager.initialize(MasterPageManager.java:95) at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:226) at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:193) at org.apache.poi.xwpf.converter.xhtml.XHTMLConverter.convert(XHTMLConverter.java:68) at org.apache.poi.xwpf.converter.xhtml.XHTMLConverter.doConvert(XHTMLConverter.java:58) at org.apache.poi.xwpf.converter.xhtml.XHTMLConverter.doConvert(XHTMLConverter.java:38) at org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45) at com.maximintegrated.wcm.handlers.SoftwarePartDownloadHandler.wordFileFrmURLToHTML(SoftwarePartDownloadHandler.java:112) at com.maximintegrated.wcm.handlers.SoftwarePartDownloadHandler.activate(SoftwarePartDownloadHandler.java:56)
Solved! Go to Solution.
Hi,
What you need to do is properly embed the required jars in your bundle. You must keep in mind that it will not only be the jars you directly depend on, but also that jar's transitive dependencies.
in your pom you will need to embed like this in the configuration instructions for the maven-bundle-plugin:
<configuration><instructions><Bundle-Category>granite,workflow</Bundle-Category><Embed-Dependency>*;scope=compile</Embed-Dependency> <Embed-Dependency>*;scope=compile</Embed-Dependency> <Embed-Transitive>true</Embed-Transitive>
</instructions></configuration>
I use the scope=compile trick so that all of the compile scoped dependencies are included.
If the dependencies you are including are large and have lots of transitive dependencies, you may need to exclude some parts, whcih can be done by adding this to the instructions: (sometimes needed for dependencies which are not needed)
<Import-Package>!org.apache.tools.ant.*,!org.objectweb.asm.*,*</Import-Package>
This can be an error prone process, and might require a few iterations to get it working. Good luck.
The maven bundle plugin is documented here: http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html
Will
after building the bundle in target,check whether the class you are executing is in bundle or not...
Hi Santosh,
Actually my class is already there and from my class only the statement XHTMLConverter.getInstance().convert(document, out, options); is throwing exception as internally somehow its referring to org/openxmlformats/schemas/wordprocessingml/x2006/main/impl/CTSectPrImpl$1HeaderReferenceList which it is unable to find. So the issue is how do I make OSGi to locate this class form the jar which I have provided in <dependency> of pom.xml.
Thanks
AEM will pick up a package that is exposed by any OSGI in the AEM service container. When you deploy to Felix - are you seeing missing packages?
Views
Replies
Total Likes
Hi,
What you need to do is properly embed the required jars in your bundle. You must keep in mind that it will not only be the jars you directly depend on, but also that jar's transitive dependencies.
in your pom you will need to embed like this in the configuration instructions for the maven-bundle-plugin:
<configuration><instructions><Bundle-Category>granite,workflow</Bundle-Category><Embed-Dependency>*;scope=compile</Embed-Dependency> <Embed-Dependency>*;scope=compile</Embed-Dependency> <Embed-Transitive>true</Embed-Transitive>
</instructions></configuration>
I use the scope=compile trick so that all of the compile scoped dependencies are included.
If the dependencies you are including are large and have lots of transitive dependencies, you may need to exclude some parts, whcih can be done by adding this to the instructions: (sometimes needed for dependencies which are not needed)
<Import-Package>!org.apache.tools.ant.*,!org.objectweb.asm.*,*</Import-Package>
This can be an error prone process, and might require a few iterations to get it working. Good luck.
The maven bundle plugin is documented here: http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html
Will
I am not seeing any missing package and OSGi AEM is unable to locate the class. Because may be I am not directly using that class from my code but its being referred to by some other class internally.
Hi Will,
I tried the way you have suggested and changed like below but unfortunately still getting the same error. Earlier I tried with
<Embed-Dependency>*;scope=compile</scope> as well but because of that lot of "Cannot be resolved" errors in bundle came up due to which I changed it to <Embed-Dependency>ooxml-schemas;scope=compile</scope>.
Do you see anything else which I can try out.
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> <Bundle-SymbolicName>my-group-id.myproject-bundle</Bundle-SymbolicName> <Bundle-Category>cq5</Bundle-Category> <Embed-Dependency>ooxml-schemas;scope=compile</Embed-Dependency> <Embed-Transitive>true</Embed-Transitive> </instructions> </configuration> </plugin>
Hi,
Since, Apache POI works fine and able to read doc files in an independent project, then we need to verify two things:
---
Jitendra
Jitendra S.Tomar wrote...
Hi,
Since, Apache POI works fine and able to read doc files in an independent project, then we need to verify two things:
Apache Felix already has POI in their container so don't override it in the OSGI container.
Compare the POI version in Felix console and Make sure, you have used same POI version in your maven dependency.
Make sure you have MS office installed in your environment. FYI: If you are using Office Libra, etc. Then Apache POI does not work properly.
---
Jitendra
Hi Jitendra,
Thanks a lot for helping me, I have few questions :
1. I can see that the bundle OSGi bundle wrapper for the Apache POI library (com.adobe.granite.poi) has all the dependencies already embedded in it like scratchpad, xmlbeans, dom4j etc as you pointed out correctly. So should I remove those from the pom.xml which I explicitly added as <dependency> and instead add only one <dependency> as below ?
<dependency> <groupId>com.adobe.granite</groupId> <artifactId>com.adobe.granite.poi</artifactId> <version>1.1.2</version> <scope>provided</scope> </dependency>
2. If I add above dependency Maven is unable to resolve and giving "Missing artifact" error in pom.xml http://pastebin.com/Dv0sP9iW. Where should I get this maven dependency.
3. MS Office 2013 is installed in my machine where CQ5 instance in present.
Thanks,
Pankaj
Hey Pankaj,
Yes, you should be using only one dependency (which you mentioned in your comment). Regarding missing artifact, there could be two possibilities:
These links could give more information about it.
http://stackoverflow.com/questions/6111408/maven2-missing-artifact-but-jars-are-in-place
http://stackoverflow.com/questions/18108080/errors-in-pom-xml-with-dependencies-missing-artifact
--
Jitendra
Hi Jitendra,
Seems like the version 1.1.2 is not present so I added the previous version i.e. 1.1.0 and the project compiled successfully and I even de compiled this jar to check CTSectPrImpl was present at org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.CTSectPrImpl.
<dependency> <groupId>com.adobe.granite</groupId> <artifactId>com.adobe.granite.poi</artifactId> <version>1.1.0</version> <scope>provided</scope> </dependency>
But unfortunately even after doing this again the same error came :
09.12.2015 13:38:07.114 *ERROR* [0:0:0:0:0:0:0:1 [1449648469071] GET /content/sladocumentdemo.html HTTP/1.1] com.day.cq.wcm.core.impl.WCMDeveloperModeFilter Error during include of SlingRequestPathInfo: path='/content/sladocumentdemo/jcr:content/par/sla_iframe', selectorString='null', extension='html', suffix='null' java.lang.NoClassDefFoundError: org/openxmlformats/schemas/wordprocessingml/x2006/main/impl/CTSectPrImpl$1HeaderReferenceList at org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.CTSectPrImpl.getHeaderReferenceList(Unknown Source) at org.apache.poi.xwpf.converter.core.MasterPageManager.visitHeadersFooters(MasterPageManager.java:200) at org.apache.poi.xwpf.converter.core.MasterPageManager.addSection(MasterPageManager.java:178) at org.apache.poi.xwpf.converter.core.MasterPageManager.compute(MasterPageManager.java:125) at org.apache.poi.xwpf.converter.core.MasterPageManager.initialize(MasterPageManager.java:95) at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:226) at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:193) at org.apache.poi.xwpf.converter.xhtml.XHTMLConverter.convert(XHTMLConverter.java:68) at org.apache.poi.xwpf.converter.xhtml.XHTMLConverter.doConvert(XHTMLConverter.java:58) at org.apache.poi.xwpf.converter.xhtml.XHTMLConverter.doConvert(XHTMLConverter.java:38) at org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45) at com.testcompany.wcm.handlers.SoftwarePartDownloadHandler.wordFileFrmURLToHTML(SoftwarePartDownloadHandler.java:114) at com.testcompany.wcm.handlers.SoftwarePartDownloadHandler.activate(SoftwarePartDownloadHandler.java:58)
Please help me why again the classdefnotfounderror is coming if the class in there in the referenced jar.
Thanks,
Pankaj
Views
Likes
Replies