I have a requirement to compile and run java programs from C# dynamically by passing parameters. Ex: below is java code i have to execute this code from c# by passing parameters num1, num2. How to do in c#?
import java.util.Scanner;
public class AddTwoNumbers2 {
public int CalAdd(int num1, int num2) {
return num1 + num2;
}
}
I am looking for calling Java code file in c# like below, python code called in c# example code
var engine = Python.CreateEngine();
var scope = engine.CreateScope();
//try
//{
var compilerOptions = (PythonCompilerOptions)engine.GetCompilerOptions();
ErrorSinkProxyListener(errorSink);
var scriptSource = engine.CreateScriptSourceFromFile(@"C:\Nidec\PythonScript\download_nrlist.py", Encoding.UTF8, Microsoft.Scripting.SourceCodeKind.File);
var compiledCode = scriptSource.Compile();
compiledCode.Execute(scope);
engine.ExecuteFile(@"C:\Nidec\PythonScript\download_nrlist.py", scope);
//get function and dynamically invoke
var calcAdd = scope.GetVariable("CalcAdd");
result = calcAdd(34, 8); // returns 42 (Int32)