Com4j vs jacob to call COM methods from Java

I support an outdated Java application that uses Jacob or Java-COM Bridge to make calls through the MS VBA and MS Word COM interfaces. I looked at com4j from Sun and it looks promising.

The reason why it suits me well is because it uses vtable binding on methods instead of IDispatch. Assuming all COM objects control the current vtable interfaces, it seems cleaner to use them instead of IDispatch. Back in the days when COM and CORBA, where hot binary technologies work, I seem to remember that early binding via vtable gave better performance than late binding via IDispatch.

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

+7
java com com + com-interop jacob
source share
2 answers

I used both Jacob and Com4j during integration with a simple COM object. I ended up with Com4j mainly because Jacob spilled too much memory. Compared to Jacob, I think Com4j was more direct when it was set up. If I remember correctly, Jacob required a lot more configuration and input before making the actual COM call. In Com4j, you just use the provided factory.

Com4j is working fine for us, but we hit several times on the road. Firstly, the created interfaces were not formed correctly, and we had to manually configure them. The main problems that I remember were that we could not properly handle the @ReturnValue annotation. In addition, we need to manually adjust the @VTID enumeration.

Another important thing that we encountered was that we could not use the Holder (out params) class for short s. We finished creating a Delphi converter, converted from Integer to Short, instead of making any changes to Com4j.

Finally, I remember that I was a little worried about the status of the project when I integrated. There seems to be no regular updates (two years since the last service release).

+13
source share

Although this is a very old question, I also recommend that new people use Com4j because it is more stable, it has an active community, and even a Maven plugin to generate your Java classes. But you can also take a look at j-interop.

0
source share

All Articles