OSGI throws a "ClassNotFoundException: org.w3c.dom. ***" Release Error

I just wrote the following codes in the 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 works fine when launched in eclipse, but when the ERRORS product is released in the log at startup:

Root exception: java.lang.NoClassDefFoundError: org / w3c / dom / Node

Called: java.lang.ClassNotFoundException: org.w3c.dom.Node

Can anybody help?

+4
source share
4 answers

OSGi provides access to system packages, but only java. * By default, this does not include other packages, such as: javax.net, javax.xml, com.sun

Therefore, you must specify any of these packages for the OSGi platform to export through the system package, which will make them available for other packages that import them.

To do this, you need to set the configuration property with the additional packages required by your packages, try setting it as a system property before starting the OSGi environment so that it picks up this property the first time it starts.

Assuming you are on OSGi 4.2, this property will be configured as follows:

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

For more details, you can check the Apache Felix Framework configuration properties , although this property is part of the OSGi specification and therefore should also be available in other implementations.

+7
source

Please update your question to include the MANIFEST.MF package.

It seems that org.w3c.dom is not implied in your products. Check the Import-Package header, you may not have Import-Package: org.w3c.dom

+1
source

If you use Equinox, you can edit config.ini and add "org.w3c.dom" to org.osgi.framework.system.packages and import the same packages into your MANIFEST.MF

0
source

in my case adding

 org.osgi.framework.bootdelegation=xx...xxx,org.w3c.dom 

solved my problem.

0
source

Source: https://habr.com/ru/post/1381076/


All Articles