2 answers
- 210
I finally found a solution to this issue. I noticed that before the NoClassDefFoundError another one was raised: a java.lang.ExceptionInInitializerError with the following cause:
Caused by: java.lang.ClassCastException: org.apache.xerces.stax.XMLEventFactoryImpl cannot be cast to javax.xml.stream.XMLEventFactory
If I understood well there is a conflict between xerces (loaded by joget) and xmlbeans (loeded by my plugin). In order to solve the conflict I excluded from xmlbeans the dependency called called stax-api:
<dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> <version>2.6.0</version> <exclusions> <exclusion> <groupId>stax</groupId> <artifactId>stax-api</artifactId> </exclusion> </exclusions> </dependency>I have been inspired by this post.
Add your comment... - 10-1
I think you need to import the package "org.apache.poi.openxml4j.opc.internal.marshallers.*" in <Import-Package> section when you build the jar file.
<Import-Package>!*,org.joget.report.dao,org.joget.report.model,org.joget.report.service,org.joget.commons.util,org.joget.plugin.base,org.joget.plugin.property.model,org.joget.plugin.property.service,org.joget.directory.model,org.joget.directory.model.service,org.joget.directory.dao,org.joget.workflow.model,org.joget.workflow.model.dao,org.joget.workflow.model.service,org.joget.workflow.util,org.joget.apps.app.dao,org.joget.apps.app.lib,org.joget.apps.app.model,org.joget.apps.app.service,org.joget.apps.datalist.lib,org.joget.apps.datalist.model,org.joget.apps.datalist.service,org.joget.apps.form.lib,org.joget.apps.form.dao,org.joget.apps.form.model,org.joget.apps.form.service,org.joget.apps.list.service,org.joget.apps.userview.lib,org.joget.apps.userview.model,org.joget.apps.userview.service,org.joget.apps.workflow.lib,org.apache.poi.openxml4j.opc.internal.marshallers.*,javax.servlet,javax.servlet.http,org.osgi.framework;version="1.3.0"</Import-Package>- Roberto Larcher
Thanks for your reply, unfortunately I get the same exeption. But, with which logic should be put packages in Import-Package? Why in particular org.apache.poi.openxml4j.opc.internal.marshallers.* and not the others I'm using? For the sake of completeness I add the stack trace of the exception. java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161) at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141) at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:72) at org.apache.poi.openxml4j.opc.OPCPackage.create(OPCPackage.java:394) at org.apache.poi.xwpf.usermodel.XWPFDocument.newPackage(XWPFDocument.java:132) at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:123) What is more frustrating is that XWPFDocument and ZipPackagePropertiesMarshaller are in the same jar. The first appears in the stack trace (therefore I suppose java finds this class) while the second generates the exception..
- Roberto Larcher
I also noticed that actually the execution generate also another exception: java.lang.ExceptionInInitializerError at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161) at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141) at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:72) at org.apache.poi.openxml4j.opc.OPCPackage.create(OPCPackage.java:394) at org.apache.poi.xwpf.usermodel.XWPFDocument.newPackage(XWPFDocument.java:132) at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:123) ..... Caused by: java.lang.ClassCastException: org.apache.xerces.stax.XMLEventFactoryImpl cannot be cast to javax.xml.stream.XMLEventFactory at javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30) at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41) ... 127 more
Add your comment...
Hi, I'm implementing a Datalist Action plugin. Everything worked well until l I included an external library. After that I get a NoClassDefFoundError exception (org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller).
This is the pom.xml file I'm using to compile the plugin (with the command 'mvn package').
And this is the jar resulting from the compilation process. If I look in the dependency folder I find the poi-ooxml-3.17, and it contains the org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller.class file.
If someone want to try to run the plugin it can be run on whatever datalist (fill randomly the mandatory options, I'm not using them yet). You can see the exception in the log file (mine is at /usr/local/tomcat/logs/joget.log)
This is the java file with the plugin implementation:
public class GenerateNewDocumentVersionDatalistAction extends DataListActionDefault { private final static String MESSAGE_PATH = "messages/GenerateNewDocumentVersionDatalistAction"; public DataListActionResult executeAction(DataList arg0, String[] arg1) { XWPFDocument xdoc = null; try { xdoc = new XWPFDocument(); } catch (Throwable e1){ LogUtil.error("Collaborative Editing - Generate new document version plugin", e1, "Error creating xwpf document"); } return null; } public String getConfirmation() { return getPropertyString("confirmation"); //get confirmation from configured properties options } public String getHref() { return getPropertyString("href"); //Let system to handle to post to the same page } public String getHrefColumn() { String recordIdColumn = getPropertyString("recordIdColumn"); //get column id from configured properties options if ("id".equalsIgnoreCase(recordIdColumn) || recordIdColumn.isEmpty()) { return getPropertyString("hrefColumn"); //Let system to set the primary key column of the binder } else { return recordIdColumn; } } public String getHrefParam() { return getPropertyString("hrefParam"); //Let system to set the parameter to the checkbox name } public String getLinkLabel() { return getPropertyString("label"); //get label from configured properties options } public String getTarget() { return "post"; } public String getClassName() { return getClass().getName(); } public String getLabel() { return AppPluginUtil.getMessage("org.joget.tutorial.GenerateNewDocumentVersionDatalistAction.pluginLabel", getClassName(), MESSAGE_PATH); } public String getPropertyOptions() { return AppUtil.readPluginResource(getClassName(), "/properties/generateNewDocumentVersionDatalisAction.json", null, true, MESSAGE_PATH); } public String getDescription() { return AppPluginUtil.getMessage("org.joget.tutorial.GenerateNewDocumentVersionDatalistAction.pluginDesc", getClassName(), MESSAGE_PATH); } public String getName() { return "New Document Generator Datalist Action"; } public String getVersion() { return "5.0.0"; }If someone can point out why this code rises this exception, please, let me know.