Posted by kohsuke
on January 8, 2008 at 10:08 AM PST
Over the weekend I made some significant progress on com4j, a bridge between Java and Windows COM API.
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 java.net 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.
- 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.
- 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.
- 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.)
- 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.
- Fixed a few more bugs in the runtime, around error handling.
com4j in maven repository
com4j is now placed in the java.net maven2 repository , and can be accessed like this: