Using IKVM to convert a JAR (Flying Saucer - xhtmlrenderer)
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)
开发者_JS百科 {
// 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?
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)
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.
精彩评论