如何从 C# 调用 Java 代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/129989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 14:53:27  来源:igfitidea点击:

How to call Java code from C#?

提问by

We've developed a Java application and would like to use this application from a C# client. The application has dependencies on Spring, Log4j, ...

我们开发了一个 Java 应用程序,并希望从 C# 客户端使用该应用程序。该应用程序依赖于 Spring、Log4j、...

What would be the most efficient mechanism - make DLL(s) from Java code, ... - to achieve this ?

什么是最有效的机制 - 从 Java 代码制作 DLL,... - 实现这一目标?

回答by MagicKat

IKVM!

IKVM!

It is really awesome. The only problem is that it DOES add ~30MB to the project. log4net and Spring .NET are available as well, but if living with existing code, go the ikvm route.

真是太棒了。唯一的问题是它确实为项目增加了约 30MB。log4net 和 Spring .NET 也可用,但如果使用现有代码,请走 ikvm 路线。

回答by Omar Kooheji

alternatively you could write a webservice/xmlrpc layer between the two.

或者,您可以在两者之间编写一个 webservice/xmlrpc 层。

I seem to remember that there is a tool calles grassshopper that will compile your .Net code into JVM bytecode.

我似乎记得有一个工具叫做蚱蜢,可以将你的 .Net 代码编译成 JVM 字节码。

I've also heard good things about IKVM

我也听说过关于 IKVM 的好消息

回答by Pavel Savara

I am author of jni4net, open source interprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.

我是jni4net 的作者,是 JVM 和 CLR 之间的开源进程间桥梁。它建立在 JNI 和 PInvoke 之上。不需要 C/C++ 代码。我希望它会帮助你。

回答by Jaye

There are so many options,

有很多选择,

  1. sockets

  2. web services

  3. Message bus

  4. Use a/any database! (sorry if sound silly)

  1. 插座

  2. 网页服务

  3. 消息总线

  4. 使用一个/任何数据库!(对不起,如果听起来很傻)

Here's a discussion which may be handy: https://gridwizard.wordpress.com/2015/01/14/java-and-dotnet-interop

这是一个可能很方便的讨论:https: //gridwizard.wordpress.com/2015/01/14/java-and-dotnet-interop

Really depends on what you're building!

真的取决于你在建造什么!