Call C# class from Java class

与世无争的帅哥 提交于 2019-12-11 03:20:51

问题


I have a java class and a c# class. I want to run that C# class from my java class.

However I don't want to pass anything from java code to c# and also don't want anything in return from C# code, I just want to run that C# code.

I want to do something like shown in below classes

Java Class:

public void static main(String[] args){

System.out.println("Running Java code ");

// here need to call C# class

}
}

I want this code to be executed from above java program

using System;
     class Program {
        Console.WriteLine("Running C# code ");
        }
    }

回答1:


You can run the C# program exe file from java code.

first compile the C#.NET program to get the Program.exe file then run the same Program.exe from java code as below:

public static void main(String[] args) throws IOException {
    // TODO code application logic here

    Process process;
    process = new ProcessBuilder("C:\\ProjectsPath\\Program.exe").start();
}

Edit:

You can send the parameters to the exe file to be invoked by passing the arguments to the ProcessBuilder constructor as below:

Note : here im passing two argumenbts to Program.exe file Name and ID :

process = new ProcessBuilder("C:\\ProjectsPath\\Program.exe" , "Sudhakar","ID501").start();


来源:https://stackoverflow.com/questions/31353829/call-c-sharp-class-from-java-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!