C# コードから Java API を呼び出したい。私の Java API は、いくつかのサードパーティ ライブラリにバンドルされた jar ファイルです。IKVM と JNI4Net を使用しようとしています。いくつかの Java 関数を呼び出すことができますが、コードがサード パーティのライブラリに依存している場合、エラーが表示されます: NoClassDefFoundError' が dll で発生しました。私の質問は、そのような JNI ベースのツールを使用して C# コードから Java アプリケーション (多くのサードパーティ ライブラリに依存する) を実行することは可能ですか?
1 に答える
0
jni4net の専門家ではありませんが、まさにそれを行った経験があります。jni4net では、BridgeSetup を使用し、そのAddClassPath()
メソッドの 1 つを呼び出して、サードパーティ ライブラリでクラスパスを構築する必要があります。
たとえば、次のようなものです。
namespace My.Lib
{
using System;
using net.sf.jni4net;
public static class MyClass
{
public static void Init()
{
// create the setup and register the Java classpath
BridgeSetup bridgeSetup = new BridgeSetup(true);
bridgeSetup.AddClassPath("lib/myLib1.jar");
bridgeSetup.AddClassPath("lib/myLib2.jar");
// add others ...
// check the actual classpath we got
Console.WriteLine("registered classpath : ");
foreach (String s in bridgeSetup.JVMCLassPath) Console.WriteLine(s);
// now create the JVM
Bridge.CreateJVM(bridgeSetup);
}
}
}
于 2015-05-08T08:20:34.043 に答える