Convert Apache POI .jar to .dll using IKVM.Net

我是研究僧i 提交于 2019-12-04 19:17:29

I just completed a project where I have successfully converted and used Apache POI 3.9 using IKVM 0.46.0.1. The converted set of DLLs support pre 2007 and post 2007 Microsoft Office formats.

Prerequisites:

Download POI 3.9 and copy all the JAR files into one directory Download IKVM (I used version 0.46.0.1) The following commands (run in Windows 7 command line in the same directory where all the POI JARs are) did the trick for me:

ikvmc -target:library xmlbeans-2.3.0.jar
ikvmc -target:library stax-api-1.0.1.jar

ikvmc poi-ooxml-schemas-3.9-20121203.jar -target:library -reference:xmlbeans-2.3.0.dll -reference:stax-api-1.0.1.dll 


ikvmc -target:library log4j-1.2.13.jar
ikvmc -target:library commons-logging-1.1.jar
ikvmc -target:library commons-codec-1.5.jar

ikvmc poi-3.9-20121203.jar -target:library -reference:log4j-1.2.13.dll -reference:commons-logging-1.1.dll -reference:commons-codec-1.5.dll

ikvmc -target:library dom4j-1.6.1.jar

ikvmc poi-ooxml-3.9-20121203.jar -target:library -reference:poi-3.9-20121203.dll -reference:poi-ooxml-schemas-3.9-20121203.dll -reference:dom4j-1.6.1.dll -reference:xmlbeans-2.3.0.dll

Hope it helps.

The -resource option of the ikvmc compiler is documented like this:

-resource:name=path Includes path as a Java resource named name

So that seems to indicate that -resource is used to include resource files into the compilation, and not (like you're doing) previously compiled DLLs.

This suspicion is confirmed by this example of how the resource option is used in an example of the ant wrapper around ikvmc:

<resource name="/logs/logging.properties" path="${builddir}/logging.properties"/>

Since ikvmc is a java-bytecode-to-.net-intermediate-language compiler, it understands how to read jar files. So instead of trying to include the (previously generated) DLLs into the compilation cycle, you should just point ikvmc to the original jar files.

The simplest way to do this is probably by converting all jars in one go:

ikvmc -target:library poi-ooxml-schemas-3.8-20120326.jar poi-3.8-20120326.jar poi-scratchpad-3.8-20120326.jar ...

You need to replace the option -resource with -reference.

But the best is to compile it in one step with { } syntax. See the wiki for details. This can look like:

ikvmc { -target:library poi-ooxml-schemas-3.8-20120326.jar } { -target:library poi-3.8-20120326.jar } { -target:library poi-scratchpad-3.8-20120326.jar } ....

Frank's answer of converting all the jars in one go solved the problem for me. Here's the full command I used for POI 3.10. All of the jars need to be in the same directory. The -out option allows you to specify the name of the output dll, otherwise it takes the name from the first jar.

ikvmc -target:library -out:poi-3.10.dll xmlbeans-2.3.0.jar stax-api-1.0.1.jar poi-ooxml-schemas-3.10-FINAL-20140208.jar log4j-1.2.13.jar commons-logging-1.1.jar commons-codec-1.5.jar poi-3.10-FINAL-20140208.jar dom4j-1.6.1.jar poi-ooxml-3.10-FINAL-20140208.jar 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!