How to use apache beanutils in a NetBeans platform project? (Error with commons-logging)
Posted
by I82Much
on Stack Overflow
See other posts from Stack Overflow
or by I82Much
Published on 2010-03-29T17:41:29Z
Indexed on
2010/03/29
17:43 UTC
Read the original article
Hit count: 394
For starters, this question is not so much about programming in the NetBeans IDE as developing a NetBeans project (e.g. using the NetBeans Platform framework).
I am attempting to use the BeanUtils library to introspect my domain models and provide the properties to display in a property sheet. Sample code:
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 have created a wrapper module around commons-beanutils-1.8.3.jar, and added a dependency on the module in my module containing the above code. Everything compiles fine. When I attempt to run the program and open the property sheet view (i.e.. the above code actually gets 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 is using the commons-logging component (wish it mentioned that in the javadoc, but that's OK). I have tried adding the commons-logging component in two different ways (creating a wrapper library around the commons-logging library, and putting a dependency on the Commons Logging Integration library).
Neither solves the problem.
Has anyone successfully used BeanUtils in a NetBeans Platform project?
© Stack Overflow or respective owner