Skip to content

Instantly share code, notes, and snippets.

@byt3bl33d3r
Forked from sixman9/java-ikvm-dotnet
Created May 31, 2021 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byt3bl33d3r/30de727bf5bf28c8cbc45fa71cd51320 to your computer and use it in GitHub Desktop.
Save byt3bl33d3r/30de727bf5bf28c8cbc45fa71cd51320 to your computer and use it in GitHub Desktop.
Using IKVM to generate a C# assembly (dll) from a Java jar file
See http://stackoverflow.com/questions/2947990/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)
{
// 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment