對於初學者包jar文件的問題,這個問題是不是這麼多在NetBeans IDE編程爲開發NetBeans項目(例如使用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 [email protected][org.apache.commons.beanutils] with possible defining loaders [[email protected][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 Integration庫)。
也不解決問題。
我注意到,與其他包裹庫出現相同的問題;如果他們自己有外部依賴關係,那麼ClassNotFoundExceptions就像瘋了一樣傳播,即使我已經包裝了他們需要的庫的罐子並將它們作爲依賴關係添加到原始包裝庫模塊。
形象地:
alt text http://files.droplr.com/files/18876491/IwG2.NetBeans%20Project%20problem.png
我在我的智慧在這裏結束。我注意到,類似的問題,而谷歌搜索:
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.
無確鑿地幫助我。
謝謝
尼克
編輯:我設法與BeanUtils的例子通過添加依賴於共享記錄和commons-收藏到的BeanUtils庫包裝進行編譯。但我的問題仍然存在於其他情況下。
在NetBeans平臺,你不只是包括原料罐;你需要創建一個包裝jar的模塊。 – I82Much 2010-03-29 18:37:53