この質問は何度も投稿されています
-Djava.library.path="./path"
が、VM ランタイム オプションに追加することで解決されました。
JNotify クラスを使用する Java でアプリを作成する必要があります。
これはサンプルコードです:
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 にライブラリをインポートした場合。
何か間違ったことをしていますか、それともすべての .jar をクラスパス システム変数に入れる必要がありますか? このアプリをリリースして、ライブラリに JNotify が含まれていない他のシステムで実行できるようにしたいと考えています。
ありがとう
Win 7 32BitでNetbeans 7.2を使用しています