Ant task for IKVMC

Description

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

Installation

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..."/>

Usage

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

The task was written for IKVM version 0.36.

Parameters

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-0.36.0.11). 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 [major.minor.build.revision] 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:

fileset

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"/>
</fileset>

reference

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"/>

resource

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

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

arg

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"/>

outputfilter

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" ...
   ...
   <outputfilter>
     <contains>class is already available in referenced assembly "IKVM.OpenJDK.ClassLibrary</contains>
     <contains>net.sf.cglib.</contains>
     <regex>^Warning IKVMC0109: class "org[.]spring[.].+$</regex>
     <wildcard>*(missing class "org.*</wildcard>
   </outputfilter>
 </ikvmc>

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

Complete Examples

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

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-0.36.0.11">
 
 <ikvmc target="library" out="${dotnet.out}/uhfclient.dll" home="${ikvm.home}" version="1.0.0.0" 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"/>
   </fileset>
 </ikvmc>

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.