开发者

com4j versus jacob to call COM methods from Java

开发者 https://www.devze.com 2022-12-16 22:25 出处:网络
I maintain a legacy Java application that uses Jacob, or Java-COM Bridge, to make calls via the COM interfaces of MS VBA and MS Word. I have开发者_StackOverflow been looking at com4j from Sun, and it

I maintain a legacy Java application that uses Jacob, or Java-COM Bridge, to make calls via the COM interfaces of MS VBA and MS Word. I have开发者_StackOverflow been looking at com4j from Sun, and it looks promising.

The reason it looks good to me is that it uses vtable binding to methods, instead of IDispatch. Assuming all the COM objects we manipulate present vtable interfaces, it seems cleaner to use them instead of IDispatch. Back in the days when COM and CORBA where the hot binary interface technologies, I seem to remember that early binding via the vtable gave better performance than late binding via IDispatch.

Has anyone migrated from Jacob to com4j? If so, what were the pitfalls and lessons learned?


I've used both Jacob and Com4j in while integration against a simple COM object. I ended up going with Com4j mainly because Jacob leaked too much memory. Compared to Jacob, I think that Com4j was more straight forward once it is set up. If I remember correctly, Jacob required much more setting up and typing before doing the actual COM call. While in Com4j you'll just use the provided factory.

Com4j has been working OK for us, but we've hit a few bumps on the way. First, the generated interfaces wasn't correctly generated and we needed to manually tweak them. The main problems I remember was that we couldn't get the @ReturnValue annotation to work properly. Also, we needed to manually correct the @VTID enumeration.

One other major thing we faced was that we couldn't use the Holder (out params) class for shorts. We ended up making a Delphi wrapper converting from Integer to Short instead of doing any changes to Com4j.

Finally, I remember that I was a bit worried about the project status while I integrated. There seems to be no regular updates (two years now since the last maintenance release).


Although it is a very old question but I also recommend new people to use Com4j because it is more stable, it has an active community and even a Maven plug-in for generating your Java classes. But you may also want to have a look at "j-interop".

0

精彩评论

暂无评论...
验证码 换一张
取 消