Ant task for IKVMC


This Ant task provides Ant interface to ikvmc, a tool converts Java bytecode to .NET dll's and exe's.


Download ant-ikvmc.jar and add the following line to your build.xml:
<taskdef name="ikvmc" classname="net.ikvm.ant.IkvmcTask" classpath="..path to ant-ikvmc.jar..."/>


If you familiar with ikvmc command line arguments, you will find task interface very simple.

The task was written for IKVM version 0.36.


Attribute Description Required
assembly Optional assembly name (otherwise it will be derived from output file name) No
classloader Specifies custom IKVM classloader for assembly. See more before use. No
debug When true, Generates debugging information in the output providing that classes are compiled with debug info. No
home Specifies root directory where IKVM is installed (For example C:\IKVM- Must be supplied if ikvmc.exe is not in your PATH. No (see desc.)
keyfile Uses keyfilename to sign the resulting assembly No
main Fully qualified name of Java main class. Used when target is "exe" and "winexe". No
nojni Do not generate JNI stub for native methods No
srcpath Specifies the location of source code. Use with debug="true". No
target Target assembly type. Supported values are exe, winexe, library, module No, default is "library"
verbose When "true" produces extra output. Usefull for debugging. No
version Assembly version in the following format: M.m.b.r [] No
  Use nested <arg> elements to define IKVMC arguments not listed above. No

For more information see ikvmc user's guide or run ikvmc.exe with no arguments.

Nested Elements

ikvmc supports the following nested elements:


Ant FileSet that specifies input Java classes, resources, and JAR files. Any fileset element that doesn't match one of (*.class, *.jar, *.zip) is considered as a resource.

This element is required. You can specify multiple fileset elements, with different base directories.

<fileset dir="lib">
    <include name="**/*.jar"/>


If your Java code uses .NET API's, specify the dll's using this option. Optional element.

<reference path="${ikvm.home}/bin/IKVM.OpenJDK.ClassLibrary.dll"/>


Each specified resource element references a Java resource to be included into output assembly. For example:

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


Optional element that defines ikvmc arguments that are not yet supported as attributes. For example, the following element appends -apartment:sta to ikvmc's command line:

<arg value="-apartment:sta"/>


Optional element that applies filters to IKVMC output. Filters are defined as sub-elements. Currently supported filters:

You can specify as many output filters as you want. For example:

 <ikvmc target="library" ...
     <contains>class is already available in referenced assembly "IKVM.OpenJDK.ClassLibrary</contains>
     <regex>^Warning IKVMC0109: class "org[.]spring[.].+$</regex>
     <wildcard>*(missing class "org.*</wildcard>

Please be aware that your filters may suppress IKVMC error diagnostic.

Complete Examples

 <ikvmc target="exe" out="hello.exe" home="c:/ikvm-" version="" debug="true" main="net.sf.ant-ikvmc.Hello">
   <fileset dir="${build}">
     <include name="**/*.class"/>
   <fileset dir="${lib}">
     <include name="**/*.jar"/>

The above example creates Windows console executable hello.exe. This executable that is generated from Java class net.sf.ant-ikvmc.Hello. It contains all java classes compiled into directory referenced by build variable and libraries that reside under directory referenced by lib variable.

 <property name="ikvm.home" location="c:/ikvm-">
 <ikvmc target="library" out="${dotnet.out}/uhfclient.dll" home="${ikvm.home}" version="" debug="true"  verbose="true">
      <reference path="${dotnet.out}/uhfc-3rd-party.dll"/>
   <fileset dir="${classes}" includes="${uhfdll.resources}">
     <include name="**/jaxb.index"/>
     <include name="**/package-info.class"/>
     <exclude name="**/*.vpp"/>
     <exclude name="**/*.txt"/>

The above example shows how to define detailed filters for input files as well as a reference to external module.

Feedback can be posted on Help forum. Sources are available on SourceForge SVN server. This small open source project is in public domain. Created by Andy Malakov.