tlbimp Ant Task

tlbimp.jar comes with an implementation of Apache Ant task so that you can integrate tlbimp into your build process easily.

To declare the tlbimp task, include the following statement in your build script:

<taskdef resource="/com4j/tlbimp/ant.properties">
  <classpath>
    <fileset dir="dir/to/com4j" includes="**/*.jar"/>
  </classpath>
</taskdef>

Synopsis

The tlbimp task supports the following attributes.

Attribute Description Required
destdir The output directory in which all the generated files will be placed. The package name will be automatically appended to this directory. Yes
package The default Java package name in which the generated types will be placed (unless overriden by <lib @package="..." />) No. Defaults to ""
locale The locale to be used to convert method names and others. This is a string like "en_US", "ja_JP", etc. No. Defaults to the system default locale

Nested Elements

lib element

A <lib> element specifies one type library to compile. Sometimes a type library depends on other type libraries. Multiple lib elements can be used in this situation to control where each of the referenced type libraries are generated.

This element can take the following attributes:

file A file that contains the type library to be processed. One of two.
libid The LIBID of the type library to be processed. A string of the form "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
libver The version of the type library given by @libid to be processed. When omitted, tlbimp searches the latest version and process it. A string of the form "major.minor" No. only valid with @libid

LIBID and LIBVER

@libid and @libver needs more explanation. Often, the location of type libraries vary from a system to system. For example, the type library for Microsoft Office is installed in the same directory where the user installed Microsoft Office. Because people install things in different places, when multiple people are working on the same project, this makes it difficult to consistently refer to the same type library.

@libid and @libver are useful in this case. Each type library has a unique GUID called "LIBID", and the version of the type library. For example, Microsoft Excel 2000 type library has the LIBID of "00020813-0000-0000-C000-000000000046" and the version of "1.3". Together they allow you to reference a type library without knowing its actual location on the disk.

To find out the LIBID, the library version, and its dependencies, use OleView.

Examples

Compile Microsoft Excel type library without refering to the file path.

<!-- compile Excel -->
<tlbimp destdir="build/src" package="excel.types">
  <lib libid="00020813-0000-0000-C000-000000000046" libver="1.3" />
</tlbimp>
Compile Microsoft PowerPoint type library and its dependencies.

<!-- compile PowerPoint -->
<tlbimp destdir="build/src">
  <lib libid="91493440-5A91-11CF-8700-00AA0060263B" package="ppt" />
  <lib libid="0002E157-0000-0000-C000-000000000046" package="vba" />
  <lib libid="2DF8D04C-5BFA-101B-BDE5-00AA0044DE52" package="office" />
</tlbimp>