我寫了個利用jacob啟動MS word,並打開相應文件的方法. 該方法在JBuilder 2005環境下能夠很順利的啟動Word並打開文件.但我把系統編譯發布後就出現問題了.程序走到"ActiveXComponent component = new ActiveXComponent(this.fileType.trim());"這句就沒有反應了.我查看了所有的環境參數都正確,我也有把jacob.jar加到Classpath,把jacob.dll加到path中.那位大俠能夠告訴我為什麼?我的程序哪裡錯了?或則可能的問題在哪裡?跪求援助!代碼如下:
public boolean openFileByJACOB(){
if (!this.validation()) return false; logger.debug("------AAAA" + this.fileType);
logger.debug(System.getProperty("java.library.path"));
System.out.println(System.getProperty("java.library.path"));
ActiveXComponent component = new ActiveXComponent(this.fileType.trim());
logger.debug("------BBBB"); try {
component.setProperty("Visible", new Variant(true));
Dispatch fileAcc = component.getProperty("Documents").toDispatch();
Dispatch file = Dispatch.invoke(fileAcc, "Open",
Dispatch.Method,
new Object[] {this.filePath,
new Variant(true),
new Variant(true)},
new int[1]).toDispatch(); Variant f = new Variant(false);
}
catch (Exception e) {
e.printStackTrace();
logger.debug(e.getMessage());
component.invoke("Quit", new Variant[] {});
return false;
}finally{
}
return true;
}
public boolean openFileByJACOB(){
if (!this.validation()) return false; logger.debug("------AAAA" + this.fileType);
logger.debug(System.getProperty("java.library.path"));
System.out.println(System.getProperty("java.library.path"));
ActiveXComponent component = new ActiveXComponent(this.fileType.trim());
logger.debug("------BBBB"); try {
component.setProperty("Visible", new Variant(true));
Dispatch fileAcc = component.getProperty("Documents").toDispatch();
Dispatch file = Dispatch.invoke(fileAcc, "Open",
Dispatch.Method,
new Object[] {this.filePath,
new Variant(true),
new Variant(true)},
new int[1]).toDispatch(); Variant f = new Variant(false);
}
catch (Exception e) {
e.printStackTrace();
logger.debug(e.getMessage());
component.invoke("Quit", new Variant[] {});
return false;
}finally{
}
return true;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货