views:

347

answers:

2

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. 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.

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

Pictorially:

alt text

I'm at my wits end here. I noticed similar problems while googling:

Is there a known bug on NB Module dependency

Same issue I'm facing but when wrapping a different jar

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

None conclusively help me.

Thank you,

Nick

EDIT: I managed to get the example with beanutils to compile by adding dependencies to commons-logging and commons-collections to the beanutils library wrapper. But my problem remains in other instances.

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

This error basically hints that the Commons Logging needs to be in the same classpath as Commons Beanutils. I am not sure what you mean with creating a wrapper module and why you would like to do it, but normally you just drop the libraries (the JAR files) in a project folder which is covered by the project's buildpath (aka classpath), or to manually add the JAR files to the project's buildpath.

BalusC
In the Netbeans Platform, you do not just include raw jars; you need to create a Module that wraps the jar.
I82Much
A: 

I rebuilt the jars, rewrapped them, and that fixed the ClassPathNotFound exceptions.

I82Much