JNI4Net C#与Java [英] JNI4Net C# To Java
问题描述
我 jniBridge.Calculator
称为一个简单的Java类,它有一个简单的方法添加(INT A,INT B)
。使用eclipse生成项目后,我出口项目作为一个JAR文件。
I have a simple Java class called jniBridge.Calculator
that has one simple method Add(int a, int b)
. After building the project using eclipse, i exported the project as a JAR file.
然后我呼吁JAR文件proxygen,这产生一个名为 CLR
和 JVM
分别在两个C#和Java代理包含所谓的另一个文件夹。 Proxygen还创建了 build.cmd
和的.xml
的文件。
I then called proxygen on the JAR file, this produced a folder called clr
and another folder called jvm
that contained both the C# and Java proxies respectively. Proxygen also created a build.cmd
and an .xml
files as well.
之后,我跑了 build.cmd
就产生了 .DLL
和 .JAR
文件。
After that i ran the build.cmd
it produced a .DLL
and .JAR
file.
现在我想用这些或任何在C#中,所以我复制的.DLL和.jar文件到在.NET项目文件夹,并添加到 .DLL
文件的引用并设置 .JAR
文件复制到复制始终
来输出文件夹,以便它沿侧存在的 .EXE
文件。我还添加了一个参考Jni4Net主库文件 jni4net.n-0.8.6.0.dll
并复制其主要的JAR文件, jni4net.j- 0.8.6.0.jar
,到同一目录。添加到转储,我还增加了原来的JAR文件我开始。
Now i want to use these or whatever in C#, so i copied the .DLL and .JAR files into the .NET project folder and added a reference to the .DLL
file and set the .JAR
file to Copy Always
to the output folder so that it exists along side the .EXE
file. I also added a reference to the Jni4Net main library file jni4net.n-0.8.6.0.dll
and copied its main JAR file, jni4net.j-0.8.6.0.jar
, to the same directory. Adding to the dump, i also added the original JAR file i started with.
在C#的Program.cs
我执行以下操作:
Inside the C# Program.cs
i do the following:
BridgeSetup bs = new BridgeSetup();
bs.AddAllJarsClassPath(".");
Bridge.CreateJVM(bs);
Bridge.RegisterAssembly(typeof(jniBridge.Calculator).Assembly);
不过,最后调用失败,出现以下异常:
However, the last invocation fails with the following exception:
未处理的异常:net.sf.jni4net.jni.JNIException:无法加载Java类的jnibridge.Calculator从类加载器sun.misc.Launcher$AppClassLoader@e39a3e --->抛出java.lang.ClassNotFoundException:jnibridge.Calculator
Unhandled Exception: net.sf.jni4net.jni.JNIException: Can't load java class for jnibridge.Calculator from classLoader sun.misc.Launcher$AppClassLoader@e39a3e ---> java.lang.ClassNotFoundException: jnibridge.Calculator
任何帮助,请!
推荐答案
我有这个问题,并固定在我的Java代码中设置小写包名(也是在C#线束参考命名空间)。在你的情况,你可以尝试并确认包名字是(完全一致)jnibridge(不JniBridge或其他任何东西)。
I had this issue, and fixed it setting the package name in lowercase in my Java code (and also the reference to the namespace in your C# harness). In your case, you might try and confirm the package name is (exactly) jnibridge (not JniBridge or anything else).
这篇关于JNI4Net C#与Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!