com4j versus jacob to call COM methods from Java
Asked Answered
C

2

8

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?

Cheder answered 14/1, 2010 at 18:0 Comment(0)
T
13

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

Torrietorrin answered 14/1, 2010 at 19:5 Comment(3)
Thanks. I didn't want to get into Jacob memory-leakage without providing details, but we've seen it, too. I think I'll do a demonstration project with com4j, and one with Jacob, and experience the differences first hand.Cheder
Im looking at going from com4j to jacob because unfortunately com4j only works with 32bit Java not 64bit Java, so seems dead in the water going forward.Doxology
As an update to the comment by @PaulTaylor com4j has since been updated with 64-bit java support.Copyholder
H
0

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

Hellas answered 6/5, 2015 at 11:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.