今天在维护一个项目的时候,突然碰到一个问题:
public Wordjdocb() {
word = new ActiveXComponent("Word.Application");
word.setProperty("Visible", new Variant(false));
documents = word.getProperty("Documents").toDispatch();
saveOnExit = false;
}
红色行先后报错:
java.lang.NoClassDefFoundError
at com.gzxf.common.word.dao.Wordjdocb.<init>(Wordjdocb.java:35)
at com.gzxf.common.word.dao.Up_visit_send.getUp_visit_send(Up_visit_send.java:65)
at com.gzxf.common.word.dao.WordDao.getUp_visit_send(WordDao.java:230)
.......
44 e.lentth39
java.lang.UnsatisfiedLinkError: no jacob in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1517)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at com.jacob.com.Dispatch.<clinit>(Dispatch.java)
at com.gzxf.common.word.dao.Wordjdocb.<init>(Wordjdocb.java:35)
at com.gzxf.common.word.dao.Up_visit_send.getUp_visit_send(Up_visit_send.java:65)
.....
at java.lang.Thread.run(Thread.java:534)
48 e.lentth39
上百度google一番后,得到解决方法:
1、确定jacob.jar在项目的lib目录下
2、把jacob.dll文件拷贝到Tomcat启动的jre/bin目录下
3、重新启动Tomcat即可!
4、如果不行就尝试继续把jacob.dll文件拷贝到jre/lib/ext目录下(我到第三步就成功了)!
PS:有些人的解决方法是把jacob.dll文件,复制到 windows\system32或者项目的src目录下。(注:我用的时候这个方法不能运行)
三种常见错误:
1、找不到jacob.dll,配置路径问题(确认jacob.dll配置正确)
java.lang.UnsatisfiedLinkError: no jacob in java.library.path
2、找不到资源文件,资源文件路径问题(查看程序中资源文件路径的设置,并检查资源文件的存放路径)
com.jacob.com.ComFailException: Invoke of: Open
3、jacob.dll或jacob.jar对应版本错误
com.jacob.com.ComFailException: A COM exception has been encountered: