gpt4 book ai didi

OSGI 在发布时暴露一个 "ClassNotFoundException: org.w3c.dom.***"错误

转载 作者:行者123 更新时间:2023-12-04 23:28:50 26 4
gpt4 key购买 nike

我只在 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

任何人都可以提供一些帮助吗?

最佳答案

OSGi 允许访问系统包,但默认情况下只有 java.* 包,这不包括其他包,如: javax.net 、 javax.xml 、 com.sun

因此,有必要为 OSGi 框架指定任何此类包,以通过系统包导出它们,从而使导入它们的其他包可以访问它们。

为此,您需要使用捆绑包所需的附加包设置配置属性,请尝试在启动 OSGi 框架之前将其设置为系统属性,以便它在首次启动时获取此属性。

假设您使用的是 OSGi 4.2,该属性将配置为:

org.osgi.framework.system.packages.extra=org.w3c.dom

您可能需要查看 Apache Felix Framework Configuration Properties有关更多详细信息,尽管此属性是 OSGi 规范的一部分,因此也应在其他实现中可用

关于OSGI 在发布时暴露一个 "ClassNotFoundException: org.w3c.dom.***"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8118404/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com