after compiling a Java library with IKVM into an DLL, I get the following error:
getResourceAsStream("path/to/resource.file") == null"
the library tries to load a Java resouce from the own jar file with the following code:
Thread.currentThread().getContextClassLoader().getResourceAsStream("path/to/resource.file")
as workaround I tried to copy the resouce file into the main directory of my .NET project and call ikvmc with the resource parameter:
ikvmc java-library.jar -target:library -resouce:/path/to/resource.file=resource.file
the strange thing is that the resulting DLL includes a resource.jar containing just an empty directory strukture /path/to/resource.file
where resource.file is not the file, but just another empty directory
is there a way to compile Java libraries with ikvmc into DLLs, where the Java code reads resource files with ContextClassLoader.getResourceAsStream()?
The problem was caused by the decission on the class loader. The Java library uses the context class loader:
Thread.currentThread().getContextClassLoader()
In IKVM it seems that this is the general class loader used for the entire .NET runtime. This one is not able to load resources from JAR files. When changing the Java library to use the same class loader that loaded the class containing the resource loading code, the resources are loaded corretly with IKVM as well:
ClassLoader currentClassLoader = MyClass.class.getClassLoader();
URL url = currentClassLoader.getResource("resource/name");