我用java构建了一个非常小且简单的helloWorld程序(有接口(interface)并且在类中有system.lang.out.println("hello world")))。我用代理生成器包装了它。现在,我尝试将其附加到 c#(以 meCalc 为例),但出现以下错误:
Unhandled Exception: net.sf.jni4net.jni.JNIException: Can't load java class for dt09120958.HelloWorld09120958 from classLoader sun.misc.Launcher$AppClassLoader@c387f44 ---> java.lang.ClassNotFoundException: dt09120958.HelloWorld09120958 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 netdt09120958.Program.Main(String[] args)
我的 C# 代码:
static void Main(string[] args)
{
var bridgeSetup = new BridgeSetup();
bridgeSetup.AddAllJarsClassPath(".");
Bridge.CreateJVM(bridgeSetup);
Bridge.RegisterAssembly(typeof(HelloWorld09120958).Assembly);
IHelloWorld09120958 calc = new HelloWorld09120958();
calc.SayHello();
Console.ReadKey();
}
为什么会这样呢?我做错了什么以及如何修复它以使其正常工作?
最佳答案
发现java包中可能不包含任何大写字母。 原始 JAR 和 j4n.jar 必须与 exe 文件位于同一文件夹中。另外,将它们添加到项目时,请确保在属性中将它们标记为“始终复制” 谢谢@Tetsuya Yamamoto
我还发现了这个链接,它可能有助于某人排除故障 http://jni4net.com/troubleshoot.html
关于java - jni4net c# 与 jni4net java.lang.ClassNotFoundException 中的 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46170693/