是否可以从 Java 调用 COM API?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/138028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to call a COM API from Java?
提问by Chris Carruthers
Is it possible to call a COM API from Java (specifically the HP/Mercury Quality Center OTA API)? If so, what's the best way?
是否可以从 Java(特别是 HP/Mercury Quality Center OTA API)调用 COM API?如果是这样,最好的方法是什么?
Is something like JACOB appropriate?
像 JACOB 这样的东西合适吗?
Code fragments would be helpful for the basics :-)
代码片段将有助于基础知识:-)
采纳答案by anjanb
jacob : yes, http://sourceforge.net/projects/jacob-project/is an active project that will suite your purpose pretty well.
jacob :是的,http: //sourceforge.net/projects/jacob-project/是一个活跃的项目,可以很好地满足您的目的。
you can see multiple examples : http://jacob-project.wiki.sourceforge.net/Event+Callbacks
您可以看到多个示例:http: //jacob-project.wiki.sourceforge.net/Event+Callbacks
but if you want something that is more tested and are willing to pay money, then go for http://www.nevaobject.com/_docs/_java2com/java2com.htm.
但是,如果您想要经过更多测试并愿意付钱的东西,请访问 http://www.nevaobject.com/_docs/_java2com/java2com.htm。
回答by user2228895
after a comparison of all the above, none was totally satisfactory.
经过以上所有的比较,没有一个是完全令人满意的。
the most complete solution is in https://github.com/java-native-access/jna
最完整的解决方案在 https://github.com/java-native-access/jna
now.
现在。
It supports,
它支持,
- getting interface to a running COM object
- starting a new COM object and returning its interface
- calling COM methods and returning results
- optional separate COM thread handling
- ComEventCallbacks
- RunninObjectTable queries
- lowlevel COM use
- util / high level java proxy abstraction
- 获取正在运行的 COM 对象的接口
- 启动一个新的 COM 对象并返回它的接口
- 调用 COM 方法并返回结果
- 可选的单独 COM 线程处理
- ComEventCallbacks
- 运行对象表查询
- 低级 COM 使用
- util / 高级 Java 代理抽象
E.g.
例如
MsWordApp comObj = this.factory.createObject(MsWordApp.class);
Documents documents = comObj.getDocuments();
_Document myDocument = documents.Add();
String path = new File(".").getAbsolutePath();
myDocument.SaveAs(path + "\abcdefg", WdSaveFormat.wdFormatPDF);
comObj.Quit();
回答by z0rglub
maybe you should have a look at http://qctools4j.sourceforge.net/it's a java library used by qclylyn (http://sourceforge.net/apps/mediawiki/qcmylyn/index.php?title=Main_Page) to retrieve defects from QC.
也许你应该看看http://qctools4j.sourceforge.net/它是 qclyyn (http://sourceforge.net/apps/mediawiki/qcmylyn/index.php?title=Main_Page) 用来检索缺陷的 Java 库来自 QC。
unfortunately the COM bridge doesn't work for linux as it loads jacob dlls
不幸的是,COM 桥在 linux 上不起作用,因为它会加载 jacob dll
回答by user266203
You can use J-Integra COM2JAVAtool. The com2java tool generates Java "proxy" classes and interfaces that correspond to the coclasses and interfaces contained in a COM type library. It effectively generates a Java API which you can use to access a COM component from Java.
您可以使用 J-Integra COM2JAVA工具。com2java 工具生成与 COM 类型库中包含的 coclass 和接口相对应的 Java“代理”类和接口。它有效地生成了一个 Java API,您可以使用它从 Java 访问 COM 组件。
回答by richj
j-Interop is a Java-COM bridge: j-Interop. It's written in pure Java and licensed under the LGPL v3. It uses the DCOM wire protocol to call COM objects as opposed to the JNI approach used by JACOB.
j-Interop 是一个 Java-COM 桥:j-Interop。它是用纯 Java 编写的,并在 LGPL v3 下获得许可。它使用 DCOM 线路协议来调用 COM 对象,而不是 JACOB 使用的 JNI 方法。

