我正在尝试调用“new XWPFDocument(inStream);”在 XPages 应用程序的 java 类中。 XWPFDocument 类是 Apache POI 库的一部分。但是,当它在运行时调用此构造函数时,我得到以下堆栈跟踪:
11/02/2014 20:57:02 HTTP JVM:java.lang.IllegalStateException:访问被拒绝(java.lang.RuntimePermission getClassLoader) 11/02/2014 20:57:02 HTTP JVM:位于 org.apache.xmlbeans.XmlBeans.getContextTypeLoader(XmlBeans.java:336) 11/02/2014 20:57:02 HTTP JVM:位于 org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument$Factory.parse(来源未知) 11/02/2014 20:57:02 HTTP JVM:位于 org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(XWPFDocument.java:134) 11/02/2014 20:57:02 HTTP JVM:位于 org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:159) ...
我已将所有必需的 jar 文件添加到包资源管理器下的“Web Content/WEB INF/lib”文件夹中,然后将它们添加到项目的 java 构建路径中。我错过了什么吗?
调用的代码是:
OutputStream outStream = response.getOutputStream();
InputStream inStream = null;
EmbeddedObject embeddedObj = null;
XWPFDocument document = null;
if (attachments.size() > 0) {
String attachmentName = attachments.get(0).toString();
embeddedObj = downloadDocument.getAttachment(attachmentName);
if (embeddedObj != null) {
inStream = embeddedObj.getInputStream();
document = new XWPFDocument(inStream);
inStream.close();
document.write(outStream);
}
}
最佳答案
添加到Domino服务器的jvm/lib/security/java.policy
文件
grant codeBase "xspnsf://server:0/<application>.nsf/WEB-INF/lib/*" {
permission java.lang.RuntimePermission "getClassLoader";
}
或者将 jar 文件放入 Domino 服务器的受信任文件夹 jvm/lib/ext
中。
关于java - Xpages运行时错误: 'java class java.lang.IllegalStateException: Access denied (java.lang.RuntimePermission getClassLoader)' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21713574/