在 java 中调用 .net 程序集的最佳且简单的方法
是否存在一种方法可以在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的方法应该是对 .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
检查此回复是否有帮助..
从 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
不需要 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 类一样。
使用示例如下:
请注意,如果可能的话,此类桥会自动将结果转换为本机 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:
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.