Skip to main content

Updates on com4j

Posted by kohsuke on January 8, 2008 at 10:08 AM PST


This work is contributed by Jason Thrasher, but apparently neither of us released it until now — he probably thought I'd do it, and I assumed he would do it. So my apologies, Jason. But in any case, the plugin is finally released to the maven2 repository, and you can see the documentation from the com4j website.

The plugin allows you to invoke tlbimp from Maven, so you can use Maven to build Java modules to interface with COM type library.

com4j type library collections

You can generate necessary Java wrappers from COM type libraries as a part of your build, but because type libraries rarely change (especially those from 3rd parties like Microsoft or Apple), it makes more sense to pre-compile them into Java and just reuse them as binaries.

This is particularly true for those huge type libraries (think Microsoft Office.) So by using maven-com4j-plugin, I started assembling interop jar files for popular type libraries. It's still small, but the list can grow, and your feedback and contributions would be welcomed. With the maven plugin, all I need to do is to write a single pom.xml. I still need to create a web page for this.

New version of com4j

I also posted a new version of com4j with several improvements.

  1. com4j.jar is now fully self-contained, and you don't need to place com4j.dll separately. Instead the jar has the dll in it, and at the runtime it will extract the dll when necessary. This change makes it easy for those who are using com4j from Maven.
  2. tlbimp now generates @DefaultValue annotation to capture the default value for a parameter. In Visual Basic you can pass parameters nominally, and when you omit parameters the default values are used automatically. In C++, parameters can be ommitted too, although it works in slightly different way. Because of this, COM APIs tend to have long parameter list where many of them are defaulted and rarely used. This doesn't work well Java, and you often needed to figure out the default value by yourself. This new annotation works as a documentation for you so that you know what value to pass in to indicate omission.
  3. tlbimp fixed a bug where it has been decoding certain value as decimal, whereas it should have been hexadecimal. Thanks to Kousuke Taniguchi for his patch (he has the same first name as I do.)
  4. VT_I8 and VT_UI8 support are added. The size difference of data types in various languages really confuse me. In Java, long is 64bit but on Visual C++ long is 32bit.
  5. Fixed a few more bugs in the runtime, around error handling.

com4j in maven repository

com4j is now placed in the maven2 repository, and can be accessed like this:

<br /><dependency><br />  <groupId>org.jvnet.com4j</groupId><br />  <artifactId>com4j</artifactId><br />  <version>20080107</version><br /></dependency><br />
Related Topics >>


Is there a com4j version that will work using 64-bit JDK? I ...

Is there a com4j version that will work using 64-bit JDK? I only can get it (com4j.dll) to load using 32-bit JDK. I kept getting the exception:

Caused by: java.lang.UnsatisfiedLinkError: C:\Users\jonesm02\.m2\repository\org\
jvnet\com4j\com4j\20080105\com4j.dll: Can't load IA 32-bit .dll on a AMD 64-bit
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(
at java.lang.ClassLoader.loadLibrary(
at java.lang.Runtime.load0(
at java.lang.System.load(
at com4j.COM4J.loadNativeLibrary(
at com4j.COM4J.(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at com.dexone.test.web.driver.QCReporter.(

this is using the plugin:



Funny you would ask this today. I'm about to release a ...

Funny you would ask this today.

I'm about to release a new version of com4j from

Nice! You are the man! When will the download be available? ...

Nice! You are the man! When will the download be available? Also, will there be a maven repo download as well?

Yes, it should.

Does the extraction of the ddl also work when the application is deployed with javawebstart?

fullung -- I know what you mean, but I can't provide responsive free support for all my hobby projects. I'm really looking for people who could join the project and help user support.

In the mean time, at least the source code is out there, so when you are stuck you can always read the code...

After reading this post I looked at com4j after trying JACOB. com4j looks great, but the absence of replies from developers on the project mailing list disappoints.

Excuse me. I encounter a problem that the app server stated exception thrown when unload com4j.dll after i restart the application from app server. Do u know how can I do?