javacppを使用しようとしていて、eclipse(+ mac OS)でいくつかの問題が発生しました。eclipseでjavacppが動作しない--ClassNotFoundException(JNIを使用)
私は、コマンドラインでこれを実行する - それは罰金に動作します:thisポスト
で提案されているように私が手
#include <string>
namespace LegacyLibrary {
class LegacyClass {
public:
const std::string& getProperty() { return property; }
void setProperty(const std::string& property) { this->property = property; }
private:
std::string property;
};
}
と
import com.googlecode.javacpp.*;
import com.googlecode.javacpp.annotation.*;
@Platform(include="LegacyLibrary.h")
@Namespace("LegacyLibrary")
public class LegacyLibrary {
public static class LegacyClass extends Pointer {
static { Loader.load(); }
public LegacyClass() { allocate(); }
private native void allocate();
public native @ByRef String getProperty();
public native void setProperty(String property);
}
public static void main(String[] args) {
LegacyClass l = new LegacyClass();
l.setProperty("Hello World!");
System.out.println(l.getProperty());
}
}
最終結果: "hello w orld "と表示されます。
今、私は私のEclipse IDEにこれを取っているし、いくつかの理由で、私はこのエラーを取得する:
Exception in thread "main" java.lang.NoClassDefFoundError: java.lang.ClassNotFoundException: com.test.LegacyLibrary
at com.googlecode.javacpp.Loader.load(Loader.java:293)
at com.googlecode.javacpp.Loader.load(Loader.java:271)
at com.test.LegacyLibrary$LegacyClass.<clinit>(LegacyLibrary.java:12)
at com.test.LegacyLibrary.main(LegacyLibrary.java:23)
Caused by: java.lang.ClassNotFoundException: com.test.LegacyLibrary
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.googlecode.javacpp.Loader.load(Loader.java:291)
... 3 more
私は、パッケージcom.testと私が置かjavacpp.jarに2つのファイルを配置しましたクラスパス ここには何かがありますか?!?!エラーメッセージは、クラスパス内の何かが間違っている(または不足している)ことを示しますが、それは何ですか? (私はまた別のフォルダのjavacpp.jarのプロパティを指し示そうとしましたが、同じエラーメッセージが表示されます)。たぶんVM引数?!?!
ありがとうございました!
注意。 JavaCPPのBuilderを再実行して、この新しいクラスの新しいネイティブライブラリを入手しましたか? –
私は同じ問題があります!あなたは解決策を見つけましたか? – mrmclovin
いいえ、私はしませんでした。もしあなたがそれを得たら - 私に知らせてください – adhg