我已经使用jni4net proxygen从Java到.NET成功生成了代理。我现在正在尝试在Visual Studio 2017中创建.NET解决方案,并在.NET控制台程序中使用Java代理。我已从proxygeneration导入.dll,并且似乎可以正常运行,因为Visual Studio正在自动填充Java类(TempClientMain
),并且未显示任何错误。
namespace ConsoleApp1
class Program
{
static void Main()
{
var setup = new BridgeSetup(string[] args);
setup.Verbose = true;
setup.AddAllJarsClassPath("./");
Bridge.CreateJVM(setup);
Bridge.RegisterAssembly(typeof(TempClientMain).Assembly);
TempClientMain test = new TempClientMain();
test.run();
}
}
但是当我构建并运行它时,我得到以下cmd输出:
loading core from C:/Users/Ruben/source/repos/ConsoleApp1/ConsoleApp1/bin/x64/Debug/jni4net.n-0.8.8.0.DLL
loading jni4net.n-0.8.8.0, Version=0.8.8.0, Culture=neutral, PublicKeyToken=134a23405600bab4 from C:\Users\Ruben\source\repos\ConsoleApp1\ConsoleApp1\bin\x64\Debug\jni4net.n-0.8.8.0.dll
loaded jni4net.n-0.8.8.0, Version=0.8.8.0, Culture=neutral, PublicKeyToken=134a23405600bab4 from C:\Users\Ruben\source\repos\ConsoleApp1\ConsoleApp1\bin\x64\Debug\jni4net.n-0.8.8.0.dll
Initialized jni4net core
core loaded from C:/Users/Ruben/source/repos/ConsoleApp1/ConsoleApp1/bin/x64/Debug/jni4net.n-0.8.8.0.DLL
clr.version :v4.0.30319
clr.arch :64bit
java.home :C:\Program Files\Java\jdk1.8.0_161
java.version :1.8.0_161
sun.arch.data.model :64
loading mediasense.j4n, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null from C:\Users\Ruben\source\repos\ConsoleApp1\ConsoleApp1\bin\x64\Debug\mediasense.j4n.dll
Unhandled Exception: net.sf.jni4net.jni.JNIException: Can't load java class for *MY TARGET PACKAGE PATH* from classLoader sun.misc.Launcher$AppClassLoader@c387f44 ---> java.lang.ClassNotFoundException: *MY TARGET PACKAGE PATH*
at net.sf.jni4net.jni.JNIEnv.ExceptionTest()
at net.sf.jni4net.jni.JNIEnv.CallObjectMethodPtr(IJvmProxy obj, MethodId methodIdNative, Value[] args)
at java.lang.ClassLoader.loadClass(String par0)
at net.sf.jni4net.utils.Registry.LoadClass(String name, ClassLoader classLoader, JNIEnv env)
--- End of inner exception stack trace ---
at net.sf.jni4net.utils.Registry.LoadClass(String name, ClassLoader classLoader, JNIEnv env)
at net.sf.jni4net.utils.Registry.RegisterClass(RegistryRecord record, ClassLoader classLoader, JNIEnv env)
at net.sf.jni4net.utils.Registry.BindJvm(RegistryRecord record, ClassLoader classLoader, JNIEnv env)
at net.sf.jni4net.utils.Registry.BindJvm(RegistryRecord record, JNIEnv env)
at net.sf.jni4net.utils.Registry.RegisterType(Type type, Boolean bindJVM, JNIEnv env)
at net.sf.jni4net.utils.Registry.RegisterAssembly(Assembly assembly, Boolean bindJVM)
at net.sf.jni4net.Bridge.RegisterAssembly(Assembly assembly)
at ConsoleApp1.Program.Main(String[] args) in C:\Users\Ruben\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 21
Press any key to continue . . .
它加载正常,但似乎找不到目标文件夹。我写了我的目标程序包路径的地方,显示了与proxygens目标文件夹相同的程序包路径(没有大写字母)。我应该把它放在哪里,以便.NET程序可以找到它?我尝试将文件夹粘贴到项目根目录和完成的构建文件夹中。当完全不包含错误时,也会出现错误。我对Visual Studio不太熟悉,所以除了粘贴它以包含它之外,还有另一种方法吗?
答案 0 :(得分:0)
我只是从Java项目的build输出文件夹中丢失了一个jar文件。令人困惑的是,程序包路径根本没有引用该jar文件,但是可以添加它。