com4j versus jacob to call COM methods from Java

旧巷老猫 提交于 2019-12-04 11:05:53

问题


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 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?


回答1:


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).




回答2:


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



来源:https://stackoverflow.com/questions/2066318/com4j-versus-jacob-to-call-com-methods-from-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!