在 java 中调用 .net 程序集的最佳且简单的方法

发布于 2024-08-04 19:30:59 字数 103 浏览 2 评论 0原文

是否存在一种方法可以在java中调用.net程序集更具体的.dll文件?

我正在开发 .net 框架,现在我需要将其迁移到 java,我可以这样做吗?我在.net 中使用c#。

Exists a way to call .net assemblies more specific .dll files in java?

I i'm developing a a framework for .net now i need to migrate it to java, i can do this? I using c# in .net.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

恍梦境° 2024-08-11 19:30:59

最简单的方法应该是对 .Net 程序集启用 COM 功能。这样您就可以像与普通 WIN32 DLL 通信一样调用任何方法。

一些示例可以在这里找到: http://www.devx.com/interop/Article/19845

Easiest way should be to COM-enable the .Net assembly. This way you can invoke any method the way you would communicate with normal WIN32 DLL's.

Some samples can be found here: http://www.devx.com/interop/Article/19845

最笨的告白 2024-08-11 19:30:59

检查此回复是否有帮助..
从 java jvm 调用 .net 程序集崩溃..

遇到了这个有趣的事情网站(可能不会直接对您有帮助)...

dotnetfromjava.dev.java.net

Check is this response is helpful..
Calling .net assembly from java jvm crashes..

Came across this interesting site (may not be directly helpful to you)...

dotnetfromjava.dev.java.net

阳光①夏 2024-08-11 19:30:59

不需要 COM 对象,我不会推荐任何自定义解决方案,因为这就像重新发明轮子一样。关于这种集成有很多具体的案例和细节,比如传递“ref”、“out”、通用方法等等......我建议最好的是使用 JAVA 到 .NET 的桥接,例如 < a href="http://www.javonet.com" rel="nofollow">www.javonet.com。

这是有关此解决方案的简短文章:
http://javabridges.hubpages.com/hub /Using-NET-libraries-from-JAVA-is-that-possible

还有其他这样的桥,但是使用 javonet,你可以获得非常简单的 API,使用一个 JAR 文件,你只需复制 .NET dll 并调用它直接进行,无需任何额外步骤。它支持 .NET 异常、对象处置、调用实例和静态方法(包括泛型)、设置/获取字段等等...您可以在 java 中使用 .NET dll 对象,就像它们是本机 JAVA 类一样。

使用示例如下:

//Sample Usage of .NET Random Class from JAVA using Javonet
NObject dotNetRandom = Javonet.New("System.Random");
Integer randomNumber = dotNetRandom.invoke("Next",5,10);

请注意,如果可能的话,此类桥会自动将结果转换为本机 JAVA 类型,并且与方法参数的方式相同。您可以在 Javonet 网站上的快速入门指南中阅读大量示例。

There is no need for COM objects and I would not recommend any custom solutions as it would be like reinventing the wheel. There are a lot of specific cases and details about such integration that would come up like passing by "ref", "out", generic methods etc.etc... the best I would suggest is to use JAVA to .NET bridge like www.javonet.com.

Here is short article about this solution:
http://javabridges.hubpages.com/hub/Using-NET-libraries-from-JAVA-is-that-possible

There are also other such bridges but with javonet you get very easy API that with one JAR file you can just copy your .NET dll and call it directly without any additional steps. It supports .NET exceptions, object disposing, calling instance and static methods including generics, setting/getting fields and lot more... You work with .NET dll objects in java like they were native JAVA class.

Usage Sample is like:

//Sample Usage of .NET Random Class from JAVA using Javonet
NObject dotNetRandom = Javonet.New("System.Random");
Integer randomNumber = dotNetRandom.invoke("Next",5,10);

Please notice that such bridge automatically translates results to native JAVA types if possible and the same way with methods arguments. A lot of samples you can read in quick start guide on Javonet website.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文