How to execute a Java program from C#?

前端 未结 7 2068
遥遥无期
遥遥无期 2020-11-30 01:24

Wondering if anyone knows a nice way to execute a Java command-line program from C# code at run-time ?

Is it the same as executing native .EXE files ?

Wi

相关标签:
7条回答
  • 2020-11-30 02:07

    Just for the completeness: When lauching a Swing jar from C# I found this detail: if you don't set the working directory in the ProcessStartInfo object, your shiny Swing app will launch... but with no icons and no images!!

    This is the minimal working code copied from the answers here and elsewhere on SO (works for me: Java 1.8 on Win7, mi images and icons are in a subfolder of the workingDirectory):

    ProcessStartInfo psi = new ProcessStartInfo("java.exe", " -jar \"C:\\Program Files\\Installed Shiny Swing jar app\\Myjar.jar\"");
    psi.WorkingDirectory = "C:\\Program Files\\Installed Shiny Swing jar app\\"; // Do not miss this line so you awesome Swing app will show default java icon and no images
    psi.CreateNoWindow = true;
    psi.UseShellExecute = false;
    Process p = new Process();
    p.StartInfo = psi;
    p.Start();
    
    0 讨论(0)
提交回复
热议问题