在 C# 中使用 Java 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/171717/
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
Using Java-classes with C#
提问by Burkhard
I have a project written in Java (>1.5).
我有一个用 Java (>1.5) 编写的项目。
Is it possible to write parts of the project with C#?
For instance the GUI and calling the methods and instantiate the classes written in java?
是否可以使用 C# 编写部分项目?
例如GUI和调用方法并实例化用java编写的类?
If yes, how?
如果是,如何?
采纳答案by Midhat
There is something called Java Language Conversion Assistantfor .NET. You can convert your Java classes to c# and start coding.
有一种叫做.NET 的Java 语言转换助手。您可以将 Java 类转换为 c# 并开始编码。
There is also something called JNBridge(not free).
还有一种叫做JNBridge(不是免费的)的东西。
回答by Jon Skeet
回答by Ilya
It seems like my solution is very limited. and apply only to specific version of java.
看来我的解决方案非常有限。并且仅适用于特定版本的 java。
I probably will stay with old good C :) Can't imagine how to work without shared libraries :)
我可能会继续使用旧的好 C :) 无法想象没有共享库如何工作 :)
This documentexplain how to create a dll from java and use it in C code. I'm not C# or java expert but i'm sure that you can load external dll's in C# as well. So not a complete solution but good starting point, IMHO. Generally dll it's a perfect way to mixing languages.
本文档解释了如何从 java 创建一个 dll 并在 C 代码中使用它。我不是 C# 或 Java 专家,但我确信您也可以在 C# 中加载外部 dll。所以不是一个完整的解决方案,而是一个好的起点,恕我直言。通常 dll 是混合语言的完美方式。
回答by Fuangwith S.
In simple way you can pack your java classes to jar file then In C# use Processclass for execute and map IO stream
以简单的方式,您可以将 java 类打包到 jar 文件中,然后在 C# 中使用Process类执行和映射 IO 流
回答by Fuangwith S.
I did some research on this a few years ago (2005 I believe) and I liked JNBridgePro as the best third party product to do this. Check it out here http://www.jnbridge.com/
几年前我对此做了一些研究(我相信是 2005 年),我喜欢 JNBridgePro 作为最好的第三方产品。在这里查看http://www.jnbridge.com/
Good luck!
祝你好运!