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

标签 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 

提前致谢!

最佳答案

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

关于java - 配置jnotify和libnotify.so时java路径错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25515260/

相关文章:

java - 序列化和通过 JDBC 将对象保存到 JAVA_OBJECT 之间的区别

android - Android Studio 可以使用 OpenJDK 还是需要 Linux 上的 Oracle JDK?

python - 如何确定单词的概率?

java - JNotify 和 File Reader 相互冲突

java - 从路由中删除方法只能通过 Postman 进行,不能通过浏览器进行

java - 在java中与支持ssl的服务器通信

java - 为什么在 System.Logger 中使用 log(DEBUG, msg) 而不是 debug(msg)?

linux - BASH shell 脚本在命令提示符下工作正常,但不适用于 crontab

java - Mac OS X 上的 JNotify?