1

我正在尝试制作一个 Jni4net 程序来充当 Java 数据库和 C# 应用程序之间的桥梁。在做了一些 Jni4net 附带的示例之后,我尝试按照本指南进行操作。在他的程序运行时彻底遵循它之后,我得到了错误:

System.IO.FileNotFoundException

我用代码尝试了不同的东西几个小时,但没有进展。这是代码,我认为我的方法没有任何问题,文件TestOne.j4n.dll确实在 location 下FourthTest/TestOne.j4n.dll。这是Bridge.LoadAndRegisterAssemblyFrom给我错误的方法。

import java.io.File;
import java.io.IOException;

import net.sf.jni4net.Bridge;

public class WriteHejsan {
    public static void main(String[] args) throws IOException{
        try{
            Bridge.setVerbose(true);
            Bridge.init();
            Bridge.setDebug(true);
        //  File proxyAssemblyFile = new File("TestOne.j4n.dll");
        //  Bridge.LoadAndRegisterAssemblyFrom(proxyAssemblyFile);
        //  Bridge.LoadAndRegisterAssemblyFrom(new java.io.File("C:/Users/Nikolai/JNIworkspace/FourthTest/TestOne.j4n.dll"));

            Bridge.LoadAndRegisterAssemblyFrom(new java.io.File("TestOne.j4n.dll"));
        //  testone.TestClass.Name();
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
}

编辑:

我得到的完整错误消息是(瑞典语中的某些部分)

loading core from C:/Windows/assembly/GAC_MSIL/jni4net.n-0.8.8.0/0.8.8.0__134a23405600bab4/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:\Windows\assembly\GAC_MSIL\jni4net.n-0.8.8.0\0.8.8.0__134a23405600bab4\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:\Windows\assembly\GAC_MSIL\jni4net.n-0.8.8.0\0.8.8.0__134a23405600bab4\jni4net.n-0.8.8.0.dll
Initialized jni4net core
core loaded from C:/Windows/assembly/GAC_MSIL/jni4net.n-0.8.8.0/0.8.8.0__134a23405600bab4/jni4net.n-0.8.8.0.dll
clr.version         :v4.0.30319
clr.arch            :64bit
java.home           :C:\Program Files\Java\jre7
java.version        :1.7.0_67
sun.arch.data.model :64
loading TestOne.j4n, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null from C:\Users\Nikolai\JNIworkspace\FourthTest\TestOne.j4n.dll
System.IO.FileNotFoundException: Det går inte att läsa in filen eller sammansättningen TestOne, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null eller ett av dess beroenden. Det går inte att hitta filen.
Filnamn: TestOne, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
vid System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
vid System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
vid System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
vid System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
vid net.sf.jni4net.utils.Registry.GetClrWrapperAttribute(Type type)
vid net.sf.jni4net.utils.Registry.RegisterWrapper(Type wrapperType, RegistryRecord& record)
vid net.sf.jni4net.utils.Registry.RegisterType(Type type, Boolean bindJVM, JNIEnv env)
vid net.sf.jni4net.utils.Registry.RegisterAssembly(Assembly assembly, Boolean bindJVM)
vid net.sf.jni4net.Bridge.RegisterAssembly(Assembly assembly)
vid net.sf.jni4net.Bridge.LoadAndRegisterAssemblyFrom(File assemblyFile)
vid net.sf.jni4net.__Bridge.LoadAndRegisterAssemblyFrom3(IntPtr __envp, JniLocalHandle __class, JniLocalHandle assemblyFile)

VARN: Loggningen av sammansättningsbindningen är inaktiverad.
Du kan aktivera felloggning för sammansättningsbindningar genom att ange registervärdet [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) till 1.
Obs! Prestanda kan försämras något med felloggning för sammansättningsbindningar.
Du kan inaktivera funktionen genom att ta bort registervärdet [HKLM\Software\Microsoft\Fusion!EnableLog].

at net.sf.jni4net.Bridge.LoadAndRegisterAssemblyFrom(Native Method)
at WriteHejsan.main(WriteHejsan.java:17)
4

2 回答 2

1

我设法解决了这个问题,我不得不将我的 c# 程序 TestOne.dll 移动到与我使用 build.cmd 创建的 TestOne.j4n.dll 相同的文件夹中

于 2014-10-13T10:53:25.773 回答
0

.dll文件放在WriteHejsan 类的项目目录下

于 2015-09-04T09:15:35.603 回答