3

I have some Java-app and a customer with some UWP-app implemented in C#, distributed through the Windows Store etc., who wants to use some pieces of my app. Those pieces are pretty OS-independent, only parsing of some special binary file formats, applying some business logic configured using YAML files and stuff. No network, GUI, only some accesses to files etc.

We currently use IKVM to make the code of interest available to C# but ran into different problems already. Some were supporting .NET Core, some had to do with the native toolchain in Release etc. While right now things seem to work after applying some workarounds, I'm looking for alternatives to IKVM already a bit.

The only thing I currently use of IKVM is simply creating a DLL of my code using ikvmc, which can then be referenced in the UWP-project. The compiler is summarized like the following:

The ikvmc tool converts Java bytecode to .NET dll's and exe's.

That's where the support to create native Windows images of GraalVM came into my mind. Others seem to already build native binaries for Windows and according to the docs, GraalVM is able to create shared libs using "--shared". From my understanding, IKVM implements a JVM in .NET and maps things as needed and possible. That sounds pretty much like what "Substrate VM" does in case of a native image, doesn't it?

This executable includes the application, the libraries, the JDK and does not run on the Java VM, but includes necessary components like memory management and thread scheduling from a different virtual machine, called “Substrate VM”. Substrate VM is the name for the runtime components (like the deoptimizer, garbage collector, thread scheduling etc.).

https://www.graalvm.org/docs/reference-manual/native-image/

So, is there any chance that a native image in form of a DLL can replace the DLL created by ikvmc currently? Did anyone try that already and has any experiences? Did anyone try already to create a native DLL and consume that in some other native Windows app? From my understanding UWP "only" applies additional restrictions which one might be able to work around again. Or is this approach totally impossible for some reasons?

Thanks all for your input!

4

2 回答 2

1

我对 IKVM 项目不是很熟悉,所以这个答案主要是关于一般问题:

你能创建一个本地 DLL/共享库并在其他一些本地 Windows 应用程序中使用它吗?

这应该是可能的。您可以将 Java 代码编译到共享库中。入口点标有@CEntrypoint注释。

然后,您可以使用生成的共享库和头文件从本机应用程序使用您的库。

这样,例如 GraalVM 发行版默认使用 GraalVM JIT 编译器:

  1. GraalVM JIT 是用 Java 编写的
  2. 与 native-image 编译为共享库
  3. 用于热点。

这是一个描述如何通过 JNI 使用 Java 的页面:https ://www.graalvm.org/reference-manual/native-image/ImplementingNativeMethodsInJavaWithSVM/

这可能与您如何使用 C# 应用程序中的共享库非常相似。

于 2020-12-04T20:25:57.687 回答
0

GraalVM 原生镜像不是很灵活,不像 IKVM.NET 镜像。除非您喜欢编写包装器和玩 P/Invoke,否则您应该坚持使用 IKVM.NET。

注意:我支持 IKVM.NET 分支

于 2020-12-03T05:07:14.323 回答