我正在尝试在firefox上的网页中查看.doc / .docx微软word文件。当所有失败时,我尝试创建一个applet,它将包含一个Word OLE实例来查看文档。
我使用:org.eclipse.swt.ole.win32.OleClientSite创建了applet,并且在eclipse中它工作正常,我可以在里面看到Word。
我创建了一个.jar文件,我试图在firefox的网页中使用applet。小程序启动但我看不到任何内容。
这是我的applet代码:
import java.applet.Applet;
public class JWordViewer extends Applet {
org.eclipse.swt.widgets.Display display;
org.eclipse.swt.widgets.Shell swtParent;
java.awt.Canvas awtParent;
public void init() {
Thread thread = new Thread(new Runnable() {
public void run() {
setLayout(new java.awt.GridLayout(1, 1));
awtParent = new java.awt.Canvas();
add(awtParent);
display = new org.eclipse.swt.widgets.Display();
swtParent = org.eclipse.swt.awt.SWT_AWT.new_Shell(display,
awtParent);
swtParent.setLayout(new org.eclipse.swt.layout.FillLayout());
org.eclipse.swt.ole.win32.OleFrame frame = new org.eclipse.swt.ole.win32.OleFrame(
swtParent, org.eclipse.swt.SWT.NONE);
org.eclipse.swt.ole.win32.OleClientSite site;
try {
site = new org.eclipse.swt.ole.win32.OleClientSite(frame,
org.eclipse.swt.SWT.NONE, "Word.Document");
} catch (org.eclipse.swt.SWTException e) {
String str = "Create OleClientSite Error" + e.toString();
System.out.println(str);
return;
}
setSize(500, 500);
validate();
site.doVerb(org.eclipse.swt.ole.win32.OLE.OLEIVERB_SHOW);
while (swtParent != null && !swtParent.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
});
thread.start();
}
public void stop() {
if (display != null && !display.isDisposed()) {
display.syncExec(new Runnable() {
public void run() {
if (swtParent != null && !swtParent.isDisposed())
swtParent.dispose();
swtParent = null;
display.dispose();
display = null;
}
});
remove(awtParent);
awtParent = null;
}
}
}
`
知道为什么不起作用?
这是Java控制台所说的内容:
basic: Told clients applet is started
Exception in thread "Thread-11" java.lang.ExceptionInInitializerError
at org.eclipse.swt.widgets.Display.<clinit>(Display.java:130)
at JWordViewer$1.run(JWordViewer.java:17)
at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission sun.arch.data.model read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:167)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:151)
at org.eclipse.swt.internal.C.<clinit>(C.java:21)
... 3 more
在我告诉它相信这个小程序之后......
答案 0 :(得分:0)
答案是:它需要在光盘上读取和执行的权限。 一种选择是签署.jar文件。另一种选择是授予光盘权限。
我用于测试第二个选项:我修改了java.policy文件: ` grant codeBase“http://localhost/-”{ permission java.io.FilePermission“&lt;&gt;”,“读,写,执行,删除”; 权限java.net.SocketPermission“”,“接受,连接,听,解决”; permission java.util.PropertyPermission“”,“读,写”; permission java.lang.RuntimePermission“*”; permission java.awt.AWTPermission“showWindowWithoutWarningBanner”; };
这就解决了。