Netbeans platforms - problems with wrapped jar files that have dependencies

To begin with, this question is not so much related to programming in the NetBeans IDE, but to the development of the NetBeans project (for example, using the platform platform NetBeans).

I am trying to use the BeanUtils library to examine my domain models and provide properties for display in a property sheet. Code example:

public class MyNode extends AbstractNode implements PropertyChangeListener { private static final PropertyUtilsBean bean = new PropertyUtilsBean(); // snip protected Sheet createSheet() { Sheet sheet = Sheet.createDefault(); Sheet.Set set = Sheet.createPropertiesSet(); APIObject obj = getLookup().lookup (APIObject.class); PropertyDescriptor[] descriptors = bean.getPropertyDescriptors(obj); for (PropertyDescriptor d : descriptors) { Method readMethod = d.getReadMethod(); Method writeMethod = d.getWriteMethod(); Class valueType = d.getClass(); Property p = new PropertySupport.Reflection(obj, valueType, readMethod, writeMethod); set.put(p); } sheet.put(set); return sheet; } 

I created a wrapper module around commons-beanutils-1.8.3.jar and added a module dependency in my module containing the above code. Everything compiles fine. When I try to run the program and open the properties sheet view (i.e. the above code does run), I get the following error:

 java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:319) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330) at java.lang.ClassLoader.loadClass(ClassLoader.java:254) at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:259) Caused: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory starting from ModuleCL@64e48e45 [org.apache.commons.beanutils] with possible defining loaders [ ModuleCL@75da931b [org.netbeans.libs.commons_logging]] and declared parents [] at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:261) at java.lang.ClassLoader.loadClass(ClassLoader.java:254) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:399) Caused: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.commons.beanutils.PropertyUtilsBean.<init>(PropertyUtilsBean.java:132) at org.myorg.myeditor.MyNode.<clinit>(MyNode.java:35) at org.myorg.myeditor.MyEditor.<init>(MyEditor.java:33) at org.myorg.myeditor.OpenEditorAction.actionPerformed(OpenEditorAction.java:13) at org.openide.awt.AlwaysEnabledAction$1.run(AlwaysEnabledAction.java:139) at org.netbeans.modules.openide.util.ActionsBridge.implPerformAction(ActionsBridge.java:83) at org.netbeans.modules.openide.util.ActionsBridge.doPerformAction(ActionsBridge.java:67) at org.openide.awt.AlwaysEnabledAction.actionPerformed(AlwaysEnabledAction.java:142) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.AbstractButton.doClick(AbstractButton.java:389) at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:95) at java.awt.MenuItem.processActionEvent(MenuItem.java:627) at java.awt.MenuItem.processEvent(MenuItem.java:586) at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:317) at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:305) [catch] at java.awt.EventQueue.dispatchEvent(EventQueue.java:638) at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:125) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) 

I understand that beanutils uses the commons-logging component. I tried to add the commons-logging component in two different ways (by creating a wrapper library around the logging library, as well as establishing a dependency on the Commons Logging integration library).

None of them solves the problem.

I noticed that the same problem occurs with other wrapped libraries; if they themselves have external dependencies, ClassNotFoundExceptions propagate like crazy, even if I wrapped the banks of the required libraries and added them as dependencies to the original wrapped library module.

Clearly:

alt text http://files.droplr.com/files/18876491/IwG2.NetBeans%20Project%20problem.png

I'm here. I noticed similar problems while searching:

Is an error known depending on the NB module

The same problem I encountered, but when packing another can

NetBeans position on this - none of the 3 apply to me.

None of them really help me.

Thanks,

Nick

EDIT: I was able to get an example with beanutils to compile by adding dependencies to public databases and collection collections in the beanutils library wrapper. But my problem remains in other cases.

+4
source share
2 answers

I rebuilt the banks, rewritten them, and fixed the ClassPathNotFound exceptions.

+2
source
 Caused: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.commons.beanutils.PropertyUtilsBean.<init>(PropertyUtilsBean.java:132) 

This error basically tells you that Commons Logging should be in the same class path as Commons Beanutils. I'm not sure what you mean by creating a wrapper module and why you would like to do this, but usually you just drop the libraries (JAR files) in the project folder, which is covered by the project build path (aka classpath) or manually add the JAR files to the project build path.

0
source

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


All Articles