配置jnotify和libnotify.so时java路径出错

时间:2014-08-26 21:15:31

标签: java linux jnotify

我开发了一个使用一些swing组件的应用程序,应用程序正在使用jnotify来监视文件夹,它在eclipse中运行正常但是当我生成jar文件并尝试在我的系统上执行该jar时它向我显示以下错误,我在解决这个错误方面做了很多努力 但它仍然给我同样的错误,请告诉我我做错了什么。

$$ java -jar DemoJFileChooser.jar 
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: net/contentobjects/jnotify/JNotifyListener 
at DemoJFileChooser.actionPerformed(DemoJFileChooser.java:124) 
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) 
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341) 
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) 
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) 
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) 
at java.awt.Component.processMouseEvent(Component.java:6505) 
at javax.swing.JComponent.processMouseEvent(JComponent.java:3311) 
at java.awt.Component.processEvent(Component.java:6270) 
at java.awt.Container.processEvent(Container.java:2229) 
at java.awt.Component.dispatchEventImpl(Component.java:4861) 
at java.awt.Container.dispatchEventImpl(Container.java:2287) 
at java.awt.Component.dispatchEvent(Component.java:4687) 
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) 
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) 
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) 
at java.awt.Container.dispatchEventImpl(Container.java:2273) 
at java.awt.Window.dispatchEventImpl(Window.java:2719) 
at java.awt.Component.dispatchEvent(Component.java:4687) 
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735) 
at java.awt.EventQueue.access$200(EventQueue.java:103) 
at java.awt.EventQueue$3.run(EventQueue.java:694) 
at java.awt.EventQueue$3.run(EventQueue.java:692) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87) 
at java.awt.EventQueue$4.run(EventQueue.java:708) 
at java.awt.EventQueue$4.run(EventQueue.java:706) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) 
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) 
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) 
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) 
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) 
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) 
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91) 
Caused by: java.lang.ClassNotFoundException: net.contentobjects.jnotify.JNotifyListener 
at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
... 37 more 

Contents of my jar is 
DemoJFileChooser.jar 
| 
|--Globals.class 
| 
|--FolderHandler$Listener.class 
| 
|--FolderHandler.class 
| 
|--DemoJFileChooser$2.class 
| 
|--DemoJFileChooser$1.class 
| 
|--DemoJFileChooser.class 
| 
|--CmdExe.class 
| 
|--.project 
| 
|--.classpath 
| 
|--META-INF 
| | 
| |--MANIFEST.MF 
| 
|--lib 
| | 
| |--swt.jar 
| | 
| |--libjnotify.so 
| | 
| |--jnotify-0.94.jar 


.classspath file content is 

<classpath><classpathentry kind="src" path="src"/><classpathentry combineaccessrules="false" exported="true" kind="src" path="/org.eclipse.swt"/><classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/><classpathentry kind="lib" path="/usr/lib/eclipse/plugins/org.eclipse.osgi_3.7.2.dist.jar" sourcepath="/usr/lib/eclipse/dropins/sdk/plugins/org.eclipse.osgi.source_3.7.2.dist.jar"/><classpathentry kind="lib" path="/usr/lib/eclipse/plugins/org.eclipse.core.commands_3.6.0.dist.jar" sourcepath="/usr/lib/eclipse/dropins/sdk/plugins/org.eclipse.core.commands.source_3.6.0.dist.jar"/><classpathentry kind="lib" path="/usr/lib/eclipse/plugins/org.eclipse.equinox.common_3.6.0.dist.jar" sourcepath="/usr/lib/eclipse/dropins/sdk/plugins/org.eclipse.equinox.common.source_3.6.0.dist.jar"/><classpathentry kind="lib" path="/usr/lib/eclipse/plugins/org.eclipse.equinox.registry_3.5.101.dist.jar" sourcepath="/usr/lib/eclipse/dropins/sdk/plugins/org.eclipse.equinox.registry.source_3.5.101.dist.jar"/><classpathentry kind="lib" path="/usr/lib/eclipse/plugins/org.eclipse.core.runtime_3.7.0.dist.jar" sourcepath="/usr/lib/eclipse/dropins/sdk/plugins/org.eclipse.core.runtime.source_3.7.0.dist.jar"/><classpathentry kind="lib" path="/usr/lib/eclipse/plugins/org.eclipse.text_3.5.101.dist.jar" sourcepath="/usr/lib/eclipse/dropins/sdk/plugins/org.eclipse.text.source_3.5.101.dist.jar"/><classpathentry kind="lib" path="/usr/lib/eclipse/plugins/org.eclipse.jface_3.7.0.dist.jar" sourcepath="/usr/lib/eclipse/dropins/sdk/plugins/org.eclipse.jface.source_3.7.0.dist.jar"/><classpathentry kind="lib" path="/usr/lib/eclipse/plugins/org.eclipse.jface.text_3.7.2.dist.jar" sourcepath="/usr/lib/eclipse/dropins/sdk/plugins/org.eclipse.jface.text.source_3.7.2.dist.jar"/><classpathentry kind="lib" path="/usr/lib/eclipse/plugins/org.eclipse.ui.workbench_3.7.1.dist.jar" sourcepath="/usr/lib/eclipse/dropins/sdk/plugins/org.eclipse.ui.workbench.source_3.7.1.dist.jar"/><classpathentry kind="lib" path="/usr/lib/eclipse/plugins/com.ibm.icu_4.4.2.v20110823.jar" sourcepath="/usr/lib/eclipse/plugins/com.ibm.icu_4.4.2.v20110823.jar"/><classpathentry kind="lib" path="/usr/lib/eclipse/plugins/org.eclipse.ui.forms_3.5.101.dist.jar" sourcepath="/usr/lib/eclipse/dropins/sdk/plugins/org.eclipse.ui.forms.source_3.5.101.dist.jar"/><classpathentry kind="lib" path="lib/jnotify-0.94.jar" sourcepath="lib/jnotify-0.94.jar"><attributes><attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="IrodsTest/lib"/></attributes></classpathentry><classpathentry kind="lib" path="lib/swt.jar"/><classpathentry kind="output" path="bin"/></classpath> 


.project file content is 

<projectDescription><name>IrodsTest</name><comment/><projects> 
</projects><buildSpec><buildCommand><name>org.eclipse.jdt.core.javabuilder</name><arguments> 
</arguments></buildCommand></buildSpec><natures><nature>org.eclipse.jdt.core.javanature</nature></natures></projectDescription 

提前致谢!

1 个答案:

答案 0 :(得分:0)

我使用Fat Jar Eclipse插件http://fjep.sourceforge.net/及其教程http://fjep.sourceforge.net/fjeptutorial.html然后我使用eclipse的导出选项并选择Runnable JAR文件,现在它工作正常,除了jar的大小现在以前的jar文件的15倍。