com4j 与 jacob 从 Java 调用 COM 方法
我维护一个旧版 Java 应用程序,它使用 Jacob 或 Java-COM 桥通过 COM 接口进行调用MS VBA 和 MS Word。我一直在关注 Sun 的 com4j,它看起来很有前途。
它对我来说看起来不错的原因是它使用 vtable 绑定到方法,而不是 IDispatch。假设我们操作的所有 COM 对象都存在 vtable 接口,那么使用它们而不是 IDispatch 似乎更干净。回到 COM 和 CORBA 作为热门二进制接口技术的时代,我似乎记得通过 vtable 进行早期绑定比通过 IDispatch 进行后期绑定具有更好的性能。
有人从 Jacob 迁移到 com4j 吗?如果是的话,有哪些陷阱和经验教训?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在集成一个简单的 COM 对象时使用了 Jacob 和 Com4j。我最终选择了 Com4j 主要是因为 Jacob 泄漏了太多内存。与 Jacob 相比,我认为 Com4j 一旦设置起来就更加直接。如果我没记错的话,Jacob 在进行实际的 COM 调用之前需要进行更多的设置和输入。在 Com4j 中,您只需使用提供的工厂即可。
Com4j 一直运行良好,但我们在使用过程中遇到了一些障碍。首先,生成的接口没有正确生成,我们需要手动调整它们。我记得的主要问题是我们无法让
@ReturnValue
注释正常工作。此外,我们需要手动更正@VTID
枚举。我们面临的另一件主要问题是我们无法将
Holder
(输出参数)类用于short
。我们最终制作了一个从 Integer 转换为 Short 的 Delphi 包装器,而不是对 Com4j 进行任何更改。最后,我记得我在集成时有点担心项目状态。似乎没有定期更新(自上次维护版本以来已有两年)。
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 forshort
s. 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).
虽然这是一个非常老的问题,但我也推荐新人使用 Com4j,因为它更稳定,它有一个活跃的社区,甚至还有一个用于生成 Java 类的 Maven 插件。但您可能还想看看“j-interop”。
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".