对于初学者来说,这个问题与其说是在 NetBeans IDE 中编程,不如说是开发一个 NetBeans 项目(例如,使用 NetBeans 平台框架)。
我正在尝试使用 BeanUtils 库来检查我的域模型并提供要在属性表中显示的属性。示例代码:
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;
}
我围绕 commons-beanutils-1.8.3.jar 创建了一个包装模块,并在包含上述代码的模块中添加了对该模块的依赖。一切都编译得很好。当我尝试运行程序并打开属性表视图(即上面的代码实际运行)时,我收到以下错误:
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)
我知道 beanutils 正在使用 commons-logging 组件。我尝试以两种不同的方式添加 commons-logging 组件(围绕 commons-logging 库创建一个包装库,并依赖于 Commons Logging Integration 库)。
两者都解决不了问题。
我注意到其他包装的库也会出现同样的问题;如果它们本身具有外部依赖项,则 ClassNotFoundExceptions 会疯狂传播,即使我已经包装了它们需要的库的 jar 并将它们作为依赖项添加到原始包装的库模块中。
图示:
替代文本 http://files.droplr.com/files/18876491/IwG2.NetBeans%20Project%20problem.png
我在我的智慧在这里结束。我在谷歌搜索时发现了类似的问题:
没有人最终帮助我。
谢谢,
缺口
编辑:我设法通过将依赖项添加到 commons-logging 和 commons-collections 到 beanutils 库包装器来编译 beanutils 的示例。但我的问题仍然存在于其他情况下。