【问题标题】:Netbeans imported JAR not loading on runNetbeans 导入的 JAR 未在运行时加载
【发布时间】:2012-12-12 23:08:36
【问题描述】:

我看到这个问题已经发布了很多次,但它已经通过添加解决了 -Djava.library.path="./path" VM 运行时选项。

我必须在 JAVA 中构建一个使用 JNotify 类的应用程序。

这是示例代码:

package test;

import net.contentobjects.jnotify.JNotify;
import net.contentobjects.jnotify.JNotifyListener;

/**
 *
 * @author 
 */
public class Test {

    public void jnotifydemo() throws Exception {
    // path to watch
    String path = System.getProperty("user.home");

    // watch mask, specify events you care about,
    // or JNotify.FILE_ANY for all events.
    int mask = JNotify.FILE_CREATED
        | JNotify.FILE_DELETED
        | JNotify.FILE_MODIFIED
        | JNotify.FILE_RENAMED;

    // watch subtree?
    boolean watchSubtree = true;

    // add actual watch
    int watchID = JNotify.addWatch(path, mask, watchSubtree, new Listener());

    // sleep a little, the application will exit if you
    // don't (watching is asynchronous), depending on your
    // application, this may not be required
    Thread.sleep(1000000);

    // to remove watch the watch
    boolean res = JNotify.removeWatch(watchID);
    if (!res) {
        // invalid watch ID specified.
    }
    }

    class Listener implements JNotifyListener {

    public void fileRenamed(int wd, String rootPath, String oldName,
        String newName) {
        print("renamed " + rootPath + " : " + oldName + " -> " + newName);
    }

    public void fileModified(int wd, String rootPath, String name) {
        print("modified " + rootPath + " : " + name);
    }

    public void fileDeleted(int wd, String rootPath, String name) {
        print("deleted " + rootPath + " : " + name);
    }

    public void fileCreated(int wd, String rootPath, String name) {
        print("created " + rootPath + " : " + name);
    }

    void print(String msg) {
        System.err.println(msg);
    }
    }

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) throws Exception {
    System.out.println("Hello World");
    new Test().jnotifydemo();
    }
}

当我运行它时,我得到:

Error loading library, java.library.path=C:\Program Files\Java\jdk1.6.0_26\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;(continues)
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnotify in java.library.path

我已经设置了一个 Netbeans 项目并将 JAR 文件添加到项目中,以便 JAR 正确地位于我的项目的 lib/ 文件夹中,并且所有内容都在 NETBEANS 中设置。

如果设置了 java VM 的 -Djava.library.path="./path" 参数,这将正常工作,但是如果我在 NETBEANS 中导入我的 lib,应该自动包含在路径中。

我做错了什么,或者有必要将每个 .jar 放在类路径系统变量中?我想发布这个应用程序,以便它可以在其库中没有 JNotify 的其他系统上运行。

谢谢

我在 Win 7 32Bit 上使用 Netbeans 7.2

【问题讨论】:

    标签: java netbeans classpath netbeans-7


    【解决方案1】:

    您将 java jar 文件作为库弄乱了,只能在 netbeans 类路径中添加:

    只需在 NetBeans 中的项目属性上单击并调整具有您的 JAR 文件的库。

    对于本机库(so、dll、...),您需要设置:-Djava.library.path。正如你在问题中所做的那样。

    所以你有两个步骤:
    1. 从http://sourceforge.net/projects/jnotify/files/jnotify/jnotify-0.94/jnotify-lib-0.94.zip/download 将 jnotify-0.94.jar 添加到您的库中,如上图所示(这将自动更新您的类路径)
    2. jnotify.dll 或 jnotify_64bit.dll 用于 64 位 Windows 位置是某个目录,并将其添加到您的 -Djava.library.path - 将此添加到项目属性的 VM 选项中

    【讨论】:

    • 好的,我已经将 JAR 添加到库中,但奇怪的是它不起作用。它看起来编译正常,但是当我尝试运行它时出现错误
    • 此外,当我尝试使用 java -classpath "lib/jnotify-0.94.jar" -jar jntest.jar 运行 VM 时,它给了我同样的错误:错误加载库...
    • 您需要将 dll - 本机库添加到 -Djava.library.path="./path_to_dll" 以便将 DLL 链接到您的 JVM
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    • 1970-01-01
    • 2019-06-23
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多