开发者

Java classes can't get the resources in JAR files that compiled with IKVM

开发者 https://www.devze.com 2023-04-11 14:20 出处:网络
I\'ve converted a java library succesfully with ikvmc. Java library uses some resources inside its self jar file. I can reach all classes of this java library, but if I call a method that call开发者_高
I've converted a java library succesfully with ikvmc. Java library uses some resources inside its self jar file. I can reach all classes of this java library, but if I call a method that call开发者_高级运维s this.getClass().getResource(), it doens't search these resources in the assembly or the jar file in the assembly. But if I put these resources to same folder with the assembly, it can find the resources. But it doesn't work well everytime. For instance, it can't find the resources if I referenced the assembly in a website project(mvc). I tried to put these resources to bin folder, root folder, the view's folder, etc.(see my comment on this post)

So I need a permanent solution. The java library is an open source project. But I don't want to change the sources. Because the compiling the project needs eclipse, ant, 3rd party libs, etc. Also in the next release of the java library, I'll have to change the code and compile it.

I saw "resource" paramter of ikvmc. But I couldn't find a documentation or an example for this.

Now I'll try to implement a .net class that derived from the java class that calls getResource method. And then I'll overide the method that calls getResource method. But this isn't a permanent solution too.


I've found the solution. Actually I've found where I did wrong. First I had converted java library like this:


    ikvmc first.jar -target:library -out:main.library.dll
    ikvmc second.jar -target:library -out:second.dll -r:main.library.dll
    ikvmc third.jar -target:library -out:third.dll -r:main.library.dll

Then I had merged all these dlls with ILMerge. The problem wasn't in merging the dlls. The problem was in loading the resorces. The loader function is in main library. And the second and the third libraries use this loader function from main library. So the loader function searches for only its jar file that is first.jar. it doesn't search the other jars even if all of them is in the same merged dll. So I changed my convert script like this:


    ikvmc first.jar -target:library -out:merged.library.dll -sharedclassloader { second.jar } { third.jar }

So, all jars merged with this one line of command. Although I don't have to use ILMerge anymore. There isn't any explanation about "sharedclassloader" in ikvmc help page. I found this explanation in this page.

0

精彩评论

暂无评论...
验证码 换一张
取 消