3

I wanted to use the Flying Saucer Java API in .NET so I tried to use IKVM to convert the Flying Saucer library:

ikvmc core-renderer.jar

For some reason, IKVMC gave me an exe core-renderer.exe so I renamed it to core-renderer.dll, added to my assemblies and hacked away

using java.io;
using java.lang;
using com.lowagie.text;
using org.xhtmlrenderer.pdf;

namespace flying_saucer
{
    class FlyingSaucerApp
    {
        static void Main(string[] args)
        {
            // This works
            DocumentException dummy = new DocumentException();

            ITextRenderer renderer = new ITextRenderer();


            // For some reason, this raises NoClassDefFoundError                
            renderer.setDocument(File("hello.xhtml").toURI().toURL().toString());
        }
    }
}

For some reason, it is giving java.lang.NoClassDefFoundError: com.lowagie.text.DocumentException. I realized DocumentException is something ITextRender() may throw, but I've already included com.lowagie.text, any ideas?

kizzx2
  • 18,775
  • 14
  • 76
  • 83

2 Answers2

5

It turned out that for this particular situation, I needed to render both Flying Saucer and iText (a dependency of Flying Saucer) and have the Flying Saucer assembly reference to its dependency:

ikvmc -target:library itext.jar
ikvmc -target:library -reference:itext.dll core-renderer.jar

(For newbies: If you didn't read any documentation and are just trying the commands, you also need to make sure the DLL files accompanying IKVMC is also present -- the easiest way to do this is to dump all the IKVMC files beside your iText JAR files)

kizzx2
  • 18,775
  • 14
  • 76
  • 83
  • tried your commands but it says core-renderer.dll is an unknown filetype – Drahcir Jul 06 '10 at 15:10
  • Obviously, I made that answer in a haste :p I changed it and again obviously, the arguments should be `jar` files lol – kizzx2 Jul 06 '10 at 17:15
2

Make sure you've included IKVM.AWT.WinForms.dll, IKVM.OpenJDK.ClassLibrary.dll, IKVM.Runtime.dll and IKVM.Runtime.JNI.dll assemblies into your project. Also to avoid generating an executable and then renaming it you could specify the -target:library switch when compiling.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Thanks for the note for `-target:library`. It felt cleaner than having to rename the exe file. Still getting the mentioned error though :\ – kizzx2 Jun 02 '10 at 04:08