jacob配置方法及兩個常見錯誤解決

來源:互聯網
上載者:User
jacob配置方法及兩個常見錯誤解決

通過Jacob可以很方便的通過編程操作Word等MS組件,以前我也寫過一篇關於如何使用Jacob進行將word文檔轉為html和其他格式的文檔(

http://blog.csdn.net/guoxiaoshou2000/archive/2004/12/07/208024.aspx

);而且附上了源碼。

但是最近有些朋友跟我聯絡,說無法正確執行我提供的代碼,提示的錯誤如下:

com.jacob.com.ComFailException: Invoke Failed: Documents at com.jacob.com.Dispatch.invokev(Native Method)  at

com.jacob.activeX.ActiveXComponent.getProperty(ActiveXComponent.java) at wordtohtml.change(wordtohtml.java:62)

at wordtohtml.main(wordtohtml.java:104)

com.jacob.com.ComFailException: Invoke Failed: Quit

at com.jacob.com.Dispatch.invokev(Native Method)

at com.jacob.activeX.ActiveXComponent.invoke(ActiveXComponent.java) at wordtohtml.change(wordtohtml.java:77) at wordtohtml.main(wordtohtml.java:104)

Exception in thread "main"

這個錯誤以前我也碰到過,在這裡跟將我的解決方案說明一下。

造成這種錯誤的一種原因是jdk與你的jacob版本不相符合,如果使用jacob1.6而使用jdk1.4或以上版本,那麼肯定會出這種錯誤,解決方案可以升級你的jacob.dll版本——這個在yahoo的jacob討論群組上面可以有下載檔案名稱是:jacob_jre142fix_bin。

另外注意的是,這樣升級後仍然可能出錯,這樣的話,建議採用下面的配置方法。

jdk1.3.1_15 + jacob.jar 1.7 + jacob.dll的jacob_jre142fix_bin版本

其中jdk可以直接從sun的網站下載,下載連結為:

http://192.18.97.50/ECom/EComTicketServlet/BEGINBB924C3A202206BE2FD20BEBE583F482/-2147483648/829060395/1/557666/557654/829060395/2ts+/westCoastFSEND/j2sdk-1.3.1_15-oth-JPR/j2sdk-1.3.1_15-oth-JPR:7/j2sdk-1_3_1_15-windows-i586.exe

注意,下載完畢以後是一個檔案名稱很長的檔案,將其改名為jdk1.3.1_15.exe即可。

jacob.jar 1.7的如下:

http://danadler.com/jacob/jacobSrc_17.zip

注意,不要使用它裡面提供的jacob.dll。

jacob.dll可從yahoo的jacob討論群組下載(呵呵,給它做廣告了)。

下載完畢所有的檔案以後,將jacob.jar解壓然後將com和META-INF中的檔案分別添加到jdk的lib中的tools.jar中的對應檔案夾中(如果不想要這樣,通過環境變數設定也可以,但是嘗容易出錯),而jacob.dll則可以直接放到system32中即可。

這裡還要注意一點,如果你的jacob.jar和jacob.dll的版本不一致的話,很可能出現下面的錯誤:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jacob in java.libr

ary.path

        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1344)

        at java.lang.Runtime.loadLibrary0(Runtime.java:744)

        at java.lang.System.loadLibrary(System.java:815)

        at com.jacob.com.Dispatch.<clinit>(Dispatch.java)

        at openword.open(openword.java:12)

        at openword.main(openword.java:48)

或者:

Exception in thread "main" java.lang.UnsatisfiedLinkError: doCoInitialize
        at com.jacob.com.ComThread.doCoInitialize(Native Method)
        at com.jacob.com.ComThread.Init(ComThread.java)
        at com.jacob.com.ComThread.InitMTA(ComThread.java)
        at com.jacob.com.ROT.addObject(ROT.java)
        at com.jacob.com.JacobObject.<init>(JacobObject.java)
        at com.jacob.com.Dispatch.<init>(Dispatch.java)
        at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java)
        at openword.open(openword.java:12)
        at openword.main(openword.java:48)

這裡要特別注意這一點。

好了,到這裡所有的配置就完畢了,以上就是我的一些經驗了,如果有不對的地方請大家到我的blog(http://blog.csdn.net/guoxiaoshou2000)告訴我。

上面的方法已經經過我個人測試,這樣配置的話,應該是沒有問題了——不過如果你不能用jdk1.3那可以自己實驗其他的辦法,我這邊有時間也會繼續研究的。祝大家好運!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.