在C#程序集中引用Java DLL?

编程入门 行业动态 更新时间:2024-10-27 09:44:06
本文介绍了在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 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

  • 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.
  • 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.
  • 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 release. Here's the latest 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?

    本文发布于:2023-11-13 14:10:10,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1584528.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:程序   Java   DLL

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!