在C#程序集中引用Java DLL? [英] Reference Java DLL in C# Assembly?

查看:138
本文介绍了在C#程序集中引用Java DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处的说明,使用SimMetrics库。他们提供给这个图书馆的链接是 SourceForge 。它似乎最新版本的SimMetrics库是用Java创建的。是否可能编译java代码,然后在C#中引用它以在SQL Server 2008中用作程序集?

解决方案

最好的方法是使用最少的代码更改,将J#(现在已经过时,大部分不受支持)编译为java#






  • 这非常依赖于使用了多少图书馆。


  • 将代码转换为c#(惯用或其他)


    • 这在高度数学代码上有时可以很容易。作为一个优点,java代码可能会采用16位unicode。


  • 使用类似 IKVM 承载CLR中的java字节代码


    • 这可能是完全不可能的与sql server托管的运行时,当然我会认为性能会很差(因为你必须在每个呼叫的主机屏障之间thunk。


  • SF页面 strong 暗示存在java和.net版本。

    这是最新的。net release 文档



    但是,根据


    原始.NET实现的版本,而不是最新Java代码的转换。


    .Net实现主要是c#,所以你可以比较java实现中的最新变化,然后尝试在.Net代码中重新创建它们。由于转换为c#似乎在很大程度上是一个直接的副本,只是基于惯用的c#(骆驼壳,属性和参数名称)的基本考虑,你很有可能做到这一点。



    如果您考虑将更改提交为修补程序,这将使您有机会让别人验证您的更改,并可能会启动.Net端未来,项目将保持更密切的同步。


    There are instructions here to create a C# assembly using the SimMetrics library. The link they provided to this library is at SourceForge. It looks like the most recent version of the SimMetrics library was created in Java. Is it possibly to compile java code and then reference it in C# to be used as an assembly in SQL Server 2008?

    解决方案

    The best you can do is

    1. compile the java as J# (now obsolete and largely unsupported) with minimal code changes.
      • this is very dependent on how much of the libraries are used.
    2. convert the code to c# (idiomatic or otherwise)
      • this can sometimes be fairly easy on highly mathematical code. As an advantage the java code likely assumes 16 bit unicode as well.
    3. use something like IKVM to host the java byte code within the CLR
      • this may be outright impossible with the sql server hosted runtime, certainly I would think the performance would be poor (since you would have to 'thunk' across the hosting barrier on each call.

    The SF page strongly implies that there is both a java and a .net release.
    Here's the latest .net release and documentation

    However based on the read me file in that

    This is an updated version of the original .NET implementation and not a conversion of the newest Java Code.

    The .Net implementation is largely c# so you could diff the recent changes in the java implementation then attempt to recreate them in the .Net code. Since the conversion to c# seems to be largely a direct copy with only basic consideration given to idiomatic c# (camel casing, properties and parameter names) you stand a good chance of being able to do this.

    If you do consider submitting the changes as a patch, this would give you a chance of getting someone else to validate your changes and may jump start the .Net side of the project to be kept more closely in sync in future.

    这篇关于在C#程序集中引用Java DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆