简体   繁体   中英

How to choose a Java-COM bridge?

I have to create an application which automates Outlook and Word and I want to use Java for that task. (The only allowed alternative would be VB6, so...)

After a quick Google survey I found several libraries, but I'm not sure which one to use:

I have no idea how to compare these libraries and make an informed decision. It seems that COM4J is a little bit outdated, JACOB leaks memory (allegedly) and jacoZoom is commercial. Each and every one seems to require a lot of boilerplate code to perform a simple method call. (Which might be unavoidable given the design of COM)

Besides that I have no idea how to choose between one of them. Which one is the best?

We use Jacob in production environment and it works out pretty well. Nevertheless the projects seems to be not very active.

Speaking of which: Activity seems to be an advantage for J-Interop. We tried the project as well and it seems to work out pretty good with even better logging messages. I think we might choose J-Interop for new projects.

COM4J seems to be outdated, you're right.

As a developer seasoned in Java/Linux but ignorant in Windows, here was my experience (August 2015)...

Executive summary:

  1. Go with com4j ... with the caveat that:
  2. You may need to build the latest (unreleased) code to get some important recent fixes.

Longer story:

At first, the propensity for code involving JNI to crash inexplicably made me look for a non-JNI solution. J-Interop seemed to fit the bill.

However, as I tried to get j-interop to work, all the Windows DCOM permissions and registry crap made it a total PITA. It's different for different versions of Windows, required changes must be made as Administrator, etc. I don't understand any of this Windows crap and it makes me want to puke anyway.

I then tried com4j and it worked like a champ. This project is very nicely designed. It auto-generates Java interfaces from the DLL's you are using. COM calling convention details are declared using Java annotations on the interface methods, allowing you to tweak these if necessary (no tweaks were necessary in my case).

There are several developers on github who have forked the project and contributed back fixes, which is a healthy sign.

The only caveat is that you may require some of the recent fixes which, as of August 2015, are merged into the project but not contained in the latest release (which is from March 2014).

So you may need to do a custom build yourself, which includes building DLL's in Visual Studio, etc. Even as a Windows hater/ignorant, I was able to do this.

COM4J似乎仍然活跃 - 它已被转移到Github并有一个新的主页: http//com4j.kohsuke.org/tutorial.html

J-Integra by Intrinsyc Software http://j-integra.intrinsyc.com/ is your best option. It hides the complexity of having to know an unfamiliar programming language. It isn't dependent on JNI so you don't need to know JNI. J-Integra is also actively maintained and supported and Intrinsyc offers a pure 64-bit version for those people wanting to run in a pure 64-bit environment.

Intrinsyc offers free trials so you can test it out and see if it works before committing to any purchasing.

Companies like HP, IBM, SAP, and Oracle use it so you know its going to be fast, stable and well supported.

出现bridj也可以做一些COM互操作: https//code.google.com/p/bridj/wiki/COM#Example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM