从 VBA/VBScript/Visual Basic Classic 调用 Java 库 (JAR)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5297341/
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
Calling Java library (JAR) from VBA/VBScript/Visual Basic Classic
提问by hellboy
There is jar library
有jar库
native C++ port is not yet available (as DLL)
本机 C++ 端口尚不可用(作为 DLL)
I need to call from
我需要从
I have 3 possibilities:
我有3种可能性:
1) Wait until native port is ready 2) Use JAR library from VB via brigde (?), installed JRE required 3) Compile JAR into native DLL using GCJ and use it form VBA
1) 等到本机端口准备好 2) 通过 Brigde (?) 使用来自 VB 的 JAR 库,需要安装 JRE 3) 使用 GCJ 将 JAR 编译为本机 DLL 并从 VBA 中使用它
http://www.microsoft.com/germany/msdn/library/office/OfficeVBAUndDieWindowsAPI.mspx?mfr=true
http://www.microsoft.com/germany/msdn/library/office/OfficeVBAUndDieWindowsAPI.mspx?mfr=true
I think: pos. 1 is easy, but I must wait pos. 3 is in practice impossible
我认为: pos。1 很容易,但我必须等待 pos。3 在实践中是不可能的
Is there some ideas about pos. 2?
有没有关于 pos 的一些想法。2?
Thanks.
谢谢。
采纳答案by i_saw_drones
It depends on whether you wish to return values from the JAR file or not. If you do not, and just wish to execute a method then you can use a "Shell" (or ShellExecute) from VB as follows:
这取决于您是否希望从 JAR 文件中返回值。如果您不这样做,而只想执行一个方法,那么您可以使用 VB 中的“Shell”(或 ShellExecute),如下所示:
Shell("java.exe -jar " & <yourJARFile>)
If you do need to return a value then you will more than likely need a bridge - similar discussion here (for VB.NET, but principle is the same): Can you use Java libraries in a VB.net program?
如果你确实需要返回一个值,那么你很可能需要一个桥接器——这里有类似的讨论(对于 VB.NET,但原理是一样的):你能在 VB.net 程序中使用 Java 库吗?
Based on that most bridges that people have created are for .NET and not for VBA/6 so you would maybe need to create your own somehow, or perhaps create a .NET DLL that is then consumed by your VBA code.
基于人们创建的大多数桥梁都是为 .NET 而不是 VBA/6,因此您可能需要以某种方式创建自己的桥梁,或者创建一个 .NET DLL,然后由您的 VBA 代码使用。
回答by Christian Fries
回答by leandr0garcia
There are couple approaches to be used when you require 2 different technologies to speak, go for Objects/Methods publications using:
当您需要使用 2 种不同的技术时,可以使用几种方法,使用以下方法获取对象/方法出版物:
- Corba & (or RMI or JMS)
- SOAP
- RESTful API
- WebServices
- File Data exchange.
- IPC Pipeline
- Corba &(或 RMI 或 JMS)
- 肥皂
- RESTful API
- 网页服务
- 文件数据交换。
- 工控机管道
Depending on the complexity you will take your solution.
根据复杂性,您将采用您的解决方案。
Calling 'java.exe' runs the library in a VM, you can produce an output using a external resource but only the 3 first are meant to exchange objects in a heterogen solution.
调用“java.exe”在 VM 中运行库,您可以使用外部资源生成输出,但只有前 3 个用于交换异构解决方案中的对象。