6
votes

I have produced a fop.dll from fop-1.0 with ikvm:

ikvmc -target:library -reference:IKVM.OpenJDK.Core.dll -recurse:{myPathToJars}\*.jar -version:1.0 -out:{myPathToJars}\fop.dll


If I use my fop.dll in a Windows Application, everything works perfect.
If I use it in a Class Library, I get the following error:

"Provider com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl not found" at javax.xml.transform.TransformerFactory.newInstance()

The code line is:

TransformerFactory factory = TransformerFactory.newInstance();
Here is the code of method:
        public static void xmlToPDF(String xmlPath, String xslPath, SortedList arguments, String destPdfPath)
        {
            java.io.File xmlfile = new java.io.File(xmlPath);
            java.io.File pdffile = new java.io.File(destPdfPath);
            try
            {
                // configure fopFactory as desired
                FopFactory fopFactory = FopFactory.newInstance();

                FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
                // configure foUserAgent as desired

                // Setup output
                OutputStream outputStream = new java.io.FileOutputStream(pdffile);
                outputStream = new java.io.BufferedOutputStream(outputStream);

                try
                {
                    // Construct fop with desired output format
                    Fop fop = fopFactory.newFop("application/pdf" /*MimeConstants.MIME_PDF*/, foUserAgent, outputStream);

                    // Setup XSLT
                    TransformerFactory factory = TransformerFactory.newInstance();

                    java.io.File xsltfile = new java.io.File(xslPath);
                    Transformer transformer = factory.newTransformer(new StreamSource(xsltfile.getAbsoluteFile()));

                    // Set the value of a  in the stylesheet
                    if (arguments != null)
                    {
                        IList keys = arguments.GetKeyList();
                        foreach (var key in keys)
                        {
                            Object value = arguments[key];
                            transformer.setParameter(key.ToString(), value);
                        }

                    }

                    // Setup input for XSLT transformation
                    Source src = new StreamSource(xmlfile);

                    // Resulting SAX events (the generated FO) must be piped through to FOP
                    Result res = new SAXResult(fop.getDefaultHandler());

                    // Start XSLT transformation and FOP processing
                    transformer.transform(src, res);
                }
                catch (Exception e1)
                {
                    System.Console.WriteLine(e1.Message);
                }
                finally
                {
                    outputStream.close();
                }

            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }

I used ikvm-0.46.0.1 to make my fop.dll (based on fop 1.0). I included the following jars:

avalon-framework-4.2.0.jar
batik-all-1.7.jar
commons-io-1.3.1.jar
commons-logging-1.0.4.jar
fop.jar
serializer-2.7.0.jar
xalan-2.7.0.jar
xercesImpl-2.7.1.jar
xml-apis-1.3.04.jar
xml-apis-ext-1.3.04.jar
xmlgraphics-commons-1.4.jar

Any idea why this error occurs? Why is the behaviour different between Windows Application and Class Library?

Addition 10/19/11:
I managed to get working the following:

  • MyMainPrg (a Windows Forms Application)
  • MyFopWrapper (a Class Library that calls fop.dll)

But for my case this is not the solution, because in my target project, I have the following structure:

  • MainCmdLinePrg (a Console Application; calls DLL_1)
  • DLL_1 (calls DLLsharedFop) {there are several DLLs that can call DLLsharedFop}
  • DLLsharedFop (calls directly fop.dll; or - I don't care - might call MyFopWrapper)

Unfortunately this construct results in the error.
You can shorten to a pair (ACmdLinePrg,MyFopWrapper): already this does not work! But (MyMainPrg,MyFopWrapper) does...

4
The problem's going to be com.sun.org.apache - that should just be org.apache. No idea where it's getting the extra bit from, though.Rup
If I look in IKVM.OpenJDK.XML.Transform.dll then I clearly see the com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl class right there, yet I have the same problem. Yes the Transform dll is referenced and in the same directory.metaforge

4 Answers

5
votes

Here is how I got that error and how I resolved:

My solultion looks like this:

ClientApp (references)--> ClassLibrary1

My ClassLibrary1 public functions are using, but not exposing any IKVM related objects, therefore the caller (ClientApp) did not have to add IKVM references. All is good in compile time.

However in runtime, the situation is different. I got the same exception and realized that ClientApp also needed to reference the correct IKVM dll (IKVM.OpenJDK.XML.Transform.dll) that contains "[email protected]" namespace.

3
votes

I resolved a similar problem by adding the following before the problematic line:

var s = new [email protected]();
var t = new com.sun.org.apache.xalan.@internal.xsltc.trax.TransformerFactoryImpl();

As described here

0
votes

Do you have the dll with the missing class in your working directory?

If you have the dll then it is a classloader problem. Look in the IKVM wiki. Often the BootClassPathAssemby help.

0
votes

I was using NuGet Packages of FOP.dll v1.1.0 and IKVM pacakges of v7.1.45 in C#.NET app. I got this issue on Windows 2016 x64 server with error messages like:

------------------------------ Fop.cs (111): Provider com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl not found - at javax.xml.transform.TransformerFactory.newInstance() Fop.cs (125): Provider com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl not found - at javax.xml.parsers.SAXParserFactory.newInstance()\r\n at org.apache.avalon.framework.configuration.DefaultConfigurationBuilder..ctor(Boolean enableNamespaces)\r\n at

org.apache.avalon.framework.configuration.DefaultConfigurationBuilder..ctor()\r\n

I resolved the problem by adding those two lines at begins of procedure

[email protected] s = new [email protected]();
            com.sun.org.apache.xalan.@internal.xsltc.trax.TransformerFactoryImpl t = new com.sun.org.apache.xalan.@internal.xsltc.trax.TransformerFactoryImpl();

helpful link:

https://github.com/KevM/tikaondotnet/issues/21