怎么使用jacob,以及常见问题总结
发布时间:2025-05-24 08:14:01 发布人:远客网络
一、怎么使用jacob,以及常见问题总结
jacob是java用来与用其它语言写的dll通信的桥.
1.使用时我们必须先把jacob.dll加载到系统system32目录下,有些系统可以还需要用resvr32??.dll注册。
还有就是要把jacob.jar放到 classpath下,或者当前项目的lib库下。注意其的跟项目有关的.dll文件也一般放在system32目录下面。
ActiveXComponent comp=new ActiveXComponent("Com.Calculation");
System.out.println("The Library been loaded, and an activeX component been created");
这可能会出现一个异常:ComFailException: Can't get object clsid from progid这是因为你没有注册.dll文件或者没有正确注册;
int summation=Dispatch.call(comp,"sum",arg1,arg2).toInt();
System.out.println("Summation="+ summation); int subtraction= Dispatch.call(comp,"subtract",arg1,arg2).toInt();
System.out.println("Subtraction="+ subtraction);
int multiplication=Dispatch.call(comp,"multi",arg1,arg2).toInt();
System.out.println("Multiplication="+ multiplication);
double division=Dispatch.call(comp,"div",arg1,arg2).toDouble();
System.out.println("Division="+ division);
使用dispatch class,第一个参数是dispatch组件第二个是函数名,第三,四个是参数
Dispatch. get(object,“Property Name”);
* This class uses the the Jacob tech
* to use and interact with a Com cmponent
public static void main(String[] args){
ActiveXComponent comp=new ActiveXComponent("Com.Calculation");
System.out.println("The Library been loaded, and an activeX component been created");
//using the functions from the library:
int summation=Dispatch.call(comp,"sum",arg1,arg2).toInt();
System.out.println("Summation="+ summation);
int subtraction= Dispatch.call(comp,"subtract",arg1,arg2).toInt();
System.out.println("Subtraction="+ subtraction);
int multiplication=Dispatch.call(comp,"multi",arg1,arg2).toInt();
System.out.println("Multiplication="+ multiplication);
double division=Dispatch.call(comp,"div",arg1,arg2).toDouble();
System.out.println("Division="+ division);
/**The following code is abstract of using the get,
* when the library contains a function that return
* some kind of a struct, and then get its properties and values
// Dispatch disp=Dispatch.call(comp,"sum",100,10).toDispatch();
// DataType Var=Dispatch.get(disp,"Property Name");
二、jacob1.9 jar包和组件jacob.dll 在哪儿下载
Jacob是Java-COM Bridge的缩写,它在Java与微软的COM组件之间构建一座桥梁。使用Jacob自带的DLL动态链接库,并通过JNI的方式实现了在Java平台上对COM程序的调用。至于什么是COM组件,大家自己Google吧。
Jacob是一个开源软件,它的官方站点是:大家可以到上面下载源代码研究,也可以直接下载编译后的二进制文件。
里面有jacob(jacob.dll,jacob.jar以及API)
三、提高jacob读写word 速度
1、这个问题的确很困扰人,jacob处理word简直就是完美,word的什么功能都可以使用。比纯java实现的包好多了,而且兼容性也很好。唯一不足的就是比较慢,而且,服务器要安装office。至于服务器安装office就没什么。你看163的在线预览word就是这么干的。
2、废话说了一大堆,还是说到速度上来。慢应该是在打开word时加载太多的dll文件导致的,处理完成后又关闭。就这两项时间可以占据20%-30%以上,xp系统更慢,win7会快点。因此我们只要想办法不马上关闭word应该就可以提高一点速度。就像使用了数据库连接池一样。具体的工作我还在研究,看看能不能搞出点东西来。