[英]Is there any possibility to use JAR Files in .NET?
First of all, I want explain the initial situation of my problem.首先,我想解释一下我的问题的初始情况。 I'm aware of the non-existing interoperability between Java and .NET.
我知道 Java 和 .NET 之间不存在互操作性。 I've done a lot of research about this topic already, but couldn't find a suitable solution yet.
我已经对这个主题进行了大量研究,但还没有找到合适的解决方案。 Anyways I am convinced that there is a solution!
无论如何,我相信有一个解决方案!
I'm creating a C# library that needs access to .jar
files or more precisely it needs access to Java classes.我正在创建一个 C# 库,该库需要访问
.jar
文件,或者更准确地说,它需要访问 Java 类。 The use of Java classes in C# is very important, since I need to pass in parameters and wait for a result. C#中的Java类的使用非常重要,因为我需要传入参数并等待结果。
The following is a very simplified example of how it should ideally work.以下是一个非常简化的示例,说明它应该如何理想地工作。 Note that deviations are welcome, since they can't be excluded in the final solution.
请注意,偏差是受欢迎的,因为它们不能被排除在最终解决方案中。 The only important thing is that I can create a class instance of the Java class in C#.
唯一重要的是我可以在 ZD7EFA19FBE7D22372FDZADB6027 中创建 Java class 的 class 实例
calculation.java:计算。java:
public class Calculation
{
public int Add(Integer a, Integer b)
{
return a + b;
}
public int Subtract(Integer a, Integer b)
{
return a - b;
}
}
entrypoint.cs:入口点.cs:
// Implement / load the Java file
// like: using calculation;
public class Foo
{
public string Bar()
{
// The original constructor of the class is of course in Java
Calculation calc = new Calculation(); // Create class instance
int res = calc.Add(5, 10); // Call method
}
}
First of all I tried to integrate / load the .jar
files into Visual Studio / C# directly, but I couldn't find a way to do something like that.首先,我尝试将
.jar
文件直接集成/加载到 Visual Studio / C# 中,但我找不到这样做的方法。
Futhermore I tried to use IKVM8 to convert my .jar
files into .dll
files ( D ynamic L ink L ibrary), but the open-source project isn't maintained anymore & I get weird errors along the way.此外,我尝试使用IKVM8将我的
.jar
文件转换为.dll
文件( D动态链接库),但开源项目不再维护,并且在此过程中我遇到了奇怪的错误。
Another possible solution is to use JavaScript to create the class instances and to implement JavaScript into C#, but I think this is a very unclean way if it is possible at all. Another possible solution is to use JavaScript to create the class instances and to implement JavaScript into C#, but I think this is a very unclean way if it is possible at all.
Currently I am trying to convert the .jar
files into .dll
files again via Jni4net .目前我正在尝试通过Jni4net再次将
.jar
文件转换为.dll
文件。 However, I couldn't figure out how to use it in order to translate the .jar
files into .dll
files.但是,我不知道如何使用它来将
.jar
文件转换为.dll
文件。
I highly appreciate any suggestions, sheers!我非常感谢任何建议,纯粹的!
You should have a look at JNI (Java Native Interface), with it you can instantiate a Java VM from C# and instantiate and call Java classes.你应该看看 JNI(Java Native Interface),用它你可以从 C# 实例化一个 Java VM 并实例化和调用 Java 类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.