OSGI 暴露“ClassNotFoundException:org.w3c.dom.***”释放时出错
我只在 Activator.start() 函数中编写了以下代码
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
Node node = new Node() {
@Override
public Object setUserData(String arg0, Object arg1, UserDataHandler arg2) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setTextContent(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
@Override
public void setPrefix(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
@Override
public void setNodeValue(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
@Override
public Node replaceChild(Node arg0, Node arg1) throws DOMException {
// TODO Auto-generated method stub
return null;
}
@Override
public Node removeChild(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return null;
}
@Override
public void normalize() {
// TODO Auto-generated method stub
System.out.println("normalize 方法调用");
}
@Override
public String lookupPrefix(String arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public String lookupNamespaceURI(String arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isSupported(String arg0, String arg1) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isSameNode(Node arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEqualNode(Node arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isDefaultNamespace(String arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public Node insertBefore(Node arg0, Node arg1) throws DOMException {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean hasChildNodes() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean hasAttributes() {
// TODO Auto-generated method stub
return false;
}
@Override
public Object getUserData(String arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getTextContent() throws DOMException {
// TODO Auto-generated method stub
return null;
}
@Override
public Node getPreviousSibling() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getPrefix() {
// TODO Auto-generated method stub
return null;
}
@Override
public Node getParentNode() {
// TODO Auto-generated method stub
return null;
}
@Override
public Document getOwnerDocument() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getNodeValue() throws DOMException {
// TODO Auto-generated method stub
return null;
}
@Override
public short getNodeType() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getNodeName() {
// TODO Auto-generated method stub
return null;
}
@Override
public Node getNextSibling() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getNamespaceURI() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getLocalName() {
// TODO Auto-generated method stub
return null;
}
@Override
public Node getLastChild() {
// TODO Auto-generated method stub
return null;
}
@Override
public Node getFirstChild() {
// TODO Auto-generated method stub
return null;
}
@Override
public Object getFeature(String arg0, String arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public NodeList getChildNodes() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getBaseURI() {
// TODO Auto-generated method stub
return null;
}
@Override
public NamedNodeMap getAttributes() {
// TODO Auto-generated method stub
return null;
}
@Override
public short compareDocumentPosition(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return 0;
}
@Override
public Node cloneNode(boolean arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public Node appendChild(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return null;
}
};
node.normalize();
}
在 eclipse 环境中运行时一切顺利,但是,当发布产品时,运行时日志中出现错误:
根异常: java.lang.NoClassDefFoundError: org/w3c/dom/Node
引起者: java.lang.ClassNotFoundException: org.w3c.dom.Node
任何人都可以提供一些帮助吗?
I only wrote the following codes in Activator.start() function
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
Node node = new Node() {
@Override
public Object setUserData(String arg0, Object arg1, UserDataHandler arg2) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setTextContent(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
@Override
public void setPrefix(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
@Override
public void setNodeValue(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
@Override
public Node replaceChild(Node arg0, Node arg1) throws DOMException {
// TODO Auto-generated method stub
return null;
}
@Override
public Node removeChild(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return null;
}
@Override
public void normalize() {
// TODO Auto-generated method stub
System.out.println("normalize 方法调用");
}
@Override
public String lookupPrefix(String arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public String lookupNamespaceURI(String arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isSupported(String arg0, String arg1) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isSameNode(Node arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEqualNode(Node arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isDefaultNamespace(String arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public Node insertBefore(Node arg0, Node arg1) throws DOMException {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean hasChildNodes() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean hasAttributes() {
// TODO Auto-generated method stub
return false;
}
@Override
public Object getUserData(String arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getTextContent() throws DOMException {
// TODO Auto-generated method stub
return null;
}
@Override
public Node getPreviousSibling() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getPrefix() {
// TODO Auto-generated method stub
return null;
}
@Override
public Node getParentNode() {
// TODO Auto-generated method stub
return null;
}
@Override
public Document getOwnerDocument() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getNodeValue() throws DOMException {
// TODO Auto-generated method stub
return null;
}
@Override
public short getNodeType() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getNodeName() {
// TODO Auto-generated method stub
return null;
}
@Override
public Node getNextSibling() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getNamespaceURI() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getLocalName() {
// TODO Auto-generated method stub
return null;
}
@Override
public Node getLastChild() {
// TODO Auto-generated method stub
return null;
}
@Override
public Node getFirstChild() {
// TODO Auto-generated method stub
return null;
}
@Override
public Object getFeature(String arg0, String arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public NodeList getChildNodes() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getBaseURI() {
// TODO Auto-generated method stub
return null;
}
@Override
public NamedNodeMap getAttributes() {
// TODO Auto-generated method stub
return null;
}
@Override
public short compareDocumentPosition(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return 0;
}
@Override
public Node cloneNode(boolean arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public Node appendChild(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return null;
}
};
node.normalize();
}
Everything goes well when run in eclipse environment, but, when release the product, ERRORS in log when runs:
Root exception:
java.lang.NoClassDefFoundError: org/w3c/dom/Node
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.Node
Anyone can give some help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
OSGi 允许访问系统包,但默认情况下仅访问 java.* 包,这不包括其他包,例如: javax.net 、 javax.xml 、 com.sun
因此,有必要为 OSGi 框架指定任何此类包来导出它们通过系统捆绑包,使导入它们的其他捆绑包可以访问它们。
为此,您需要使用捆绑包所需的附加包设置一个配置属性,请尝试在启动 OSGi 框架之前将其设置为系统属性,以便它在首次启动时获取此属性。
假设您使用的是 OSGi 4.2,该属性的配置如下:
您可能需要检查 Apache Felix 框架配置属性 了解更多详细信息,尽管此属性是 OSGi 规范的一部分,因此也应该在其他实现中可用
OSGi gives access to system packages but only java.* packages by default, this does not include other packages like: javax.net , javax.xml , com.sun
Thus it is necessary to specify any of such packages for OSGi framework to export them through the system bundle making them accessible to other bundles that import them.
To do that you need to set a configuration property with the additional packages required by your bundles, try setting it as a system property before starting the OSGi framework such that it picks up this property when it first starts.
Assuming you are on OSGi 4.2, that property would be configured like:
You may want to check the Apache Felix Framework Configuration Properties for more details, though this property is part of the OSGi spec and thus should be available in other implementations as well
请更新您的问题以包含捆绑包的 MANIFEST.MF
看起来您的产品中并未隐式提供 org.w3c.dom 。检查 Import-Package 标头,可能是您没有
Import-Package: org.w3c.dom
Please update your question to include the bundle's MANIFEST.MF
It looks like org.w3c.dom is not implicitly provided in your production. Check the Import-Package header, may be you don't have
Import-Package: org.w3c.dom
如果您使用的是 Equinox,您可以编辑 config.ini 并将“org.w3c.dom”添加到 org.osgi.framework.system.packages 键中,并在 MANIFEST.MF 中导入相同的包
If you are using Equinox, you can edit the config.ini and add "org.w3c.dom" to org.osgi.framework.system.packages key and import the same packages in your MANIFEST.MF
就我而言,添加
解决了我的问题。
in my case adding
solved my problem.