plutext / docx4j.NET

docx4j is an open source (ASLv2) library for docx/pptx/xlsx, similar in concept to Open XML SDK, but with its own particular strengths including content control databinding (with OpenDoPE enhancements), XHTML import/export, PDF output, and MERGEFIELD processing. This is the .NET version of docx4j.
Apache License 2.0
70 stars 22 forks source link

Can't load presentation due to JAXBException #3

Closed maitredede closed 8 years ago

maitredede commented 8 years ago

Hi,

I am trying to use docx4j.net in my app, by using it from an assembly used as a plugin.

I use the nuget package docx4j.NET version 3.2.0.1, targeting "net452" (plain library project on framework 4.5.2). The dependencies added by nuget : IKVM 8.1.5717.0, slf4j-api 1.7.5, slf4j-NetCommonLogging 1.7.5.2.

When initializing my plugin, I followed samples (and some googling for classpath assemblies) :

            // Programmatically configure Common Logging
            // (alternatively, you could do it declaratively in app.config)
            LoggingNameValueCollection commonLoggingproperties = new LoggingNameValueCollection();
            commonLoggingproperties["showDateTime"] = "false";
            commonLoggingproperties["level"] = "INFO";
            LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(commonLoggingproperties);

            // Necessary, if slf4j-api and slf4j-NetCommonLogging are separate DLLs
            ikvm.runtime.Startup.addBootClassPathAssembly(
                System.Reflection.Assembly.GetAssembly(
                    typeof(org.slf4j.Logger)));
            ikvm.runtime.Startup.addBootClassPathAssembly(
                System.Reflection.Assembly.GetAssembly(
                    typeof(org.slf4j.impl.StaticLoggerBinder)));
            ikvm.runtime.Startup.addBootClassPathAssembly(
                System.Reflection.Assembly.GetAssembly(
                    typeof(org.slf4j.LoggerFactory)));
            ikvm.runtime.Startup.addBootClassPathAssembly(
                System.Reflection.Assembly.GetAssembly(
                    typeof(org.docx4j.jaxb.Context)));
            ikvm.runtime.Startup.addBootClassPathAssembly(
                System.Reflection.Assembly.GetAssembly(
                    typeof(org.apache.xalan.processor.TransformerFactoryImpl)));

I have also added a custom classloader to handle "docx4j.properties" file loading (stored as assembly resource), code is like PropertiesConfigurator.setDocx4jPropertiesDir.

Then I open my presentation :

PresentationMLPackage prez = (PresentationMLPackage)OpcPackage.load(new ikvm.io.InputStreamWrapper(inputstream));

Kaboom in the logs. Shortenned :

[INFO]  org.docx4j.jaxb.Context - java.vendor=Jeroen Frijters
[INFO]  org.docx4j.jaxb.Context - java.version=1.8.0
[INFO]  org.docx4j.jaxb.Context - No MOXy JAXB config found; assume not intended..
[ERROR] org.docx4j.jaxb.Context - PANIC! No suitable JAXB implementation available
[ERROR] org.docx4j.jaxb.Context - Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: Provider class c
om.sun.xml.internal.bind.v2.ContextFactory could not be instantiated: cli.System.MissingMethodException: Méthode introuvable : 'Void IKVM.Attributes.PackageList
Attribute..ctor(System.String[])'.
 - with linked exception:
[cli.System.MissingMethodException: Méthode introuvable : 'Void IKVM.Attributes.PackageListAttribute..ctor(System.String[])'.]
=======================================================(inner most exception)===
 (1) javax.xml.bind.JAXBException
================================================================================
Method        :  newInstance
Type          :  javax.xml.bind.ContextFinder
Assembly      :  IKVM.OpenJDK.XML.Bind, Version=8.1.5717.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58
Assembly Path :  D:\Perso\PiToyable\Piranha\Piranha.OpenDocument.Test\bin\x64\Debug\IKVM.OpenJDK.XML.Bind.dll
Source        :  IKVM.OpenJDK.XML.Bind
Thread        :  10 ''
Helplink      :

Message:
"Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: Provider class com.sun.xml.internal.bind.v2.Conte
xtFactory could not be instantiated: cli.System.MissingMethodException: Méthode introuvable : 'Void IKVM.Attributes.PackageListAttribute..ctor(System.String[])'
.
 - with linked exception:
[cli.System.MissingMethodException: Méthode introuvable : 'Void IKVM.Attributes.PackageListAttribute..ctor(System.String[])'.]"

Properties:
  JAXBException.Data = {
  }
  JAXBException.InnerException = ""
  JAXBException.TargetSite = "javax.xml.bind.JAXBContext newInstance(System.String, System.String, java.lang.ClassLoader, java.util.Map)"
  JAXBException.StackTrace = "   à javax.xml.bind.ContextFinder.newInstance(String , String , ClassLoader , Map )
   à javax.xml.bind.ContextFinder.find(String , String , ClassLoader , Map )
   à javax.xml.bind.JAXBContext.newInstance(String contextPath, ClassLoader classLoader, Map properties)
   à javax.xml.bind.JAXBContext.newInstance(String contextPath, ClassLoader classLoader)
   à org.docx4j.jaxb.NamespacePrefixMapperUtils.getPrefixMapper()
   à org.docx4j.jaxb.Context..cctor()"
  JAXBException.HelpLink = ""
  JAXBException.Source = "IKVM.OpenJDK.XML.Bind"

Stack Trace:
   à javax.xml.bind.ContextFinder.newInstance(String , String , ClassLoader , Map )
   à javax.xml.bind.ContextFinder.find(String , String , ClassLoader , Map )
   à javax.xml.bind.JAXBContext.newInstance(String contextPath, ClassLoader classLoader, Map properties)
   à javax.xml.bind.JAXBContext.newInstance(String contextPath, ClassLoader classLoader)
   à org.docx4j.jaxb.NamespacePrefixMapperUtils.getPrefixMapper()
   à org.docx4j.jaxb.Context..cctor()
================================================================================

Can it be related to a different IKVM version between your generated assembly (IKVM 7.3.4830, according to nuget dependency) and the latest version (IKVM 8.1.5717.0) ?

If so, can you update to latest IKVM version ? Or what is the compilation workflow to generated docx4j.net from latest version of docx4j ?

Thanks

maitredede commented 8 years ago

Hi,

Seams to be related to IKVM version. I have recompiled a docx4j with latest IKVM (see http://www.docx4java.org/forums/docx-java-f6/convert-docx4j-2-8-1-to-net-assemblies-by-using-ikvm-t1573.html) then goes OK.

The test I make : open a pptx file, convert it to SVG.

Seams to work.

plutext commented 8 years ago

That's right, you need to be using consistent version of IKVM.