Paul Kelley

Paul Kelley

  • NA
  • 5
  • 0

Calling Java Jar file from C#

May 29 2008 2:07 PM

I would like to know the correct syntax that would get C# to call on a Java Jar file.

For example, I have a jar file that I typically call as follows:

"java -jar exchgPub.jar 10.10.5.73 7676 eBudgetExchange"

I want C# to execute that command.

The code that follows, is an attempt to try and execute the command via a batch file, but nothing happens (i.e. no error, no execution of the jar, nothing...):

String pgmPath = m_launchDir + "\\java -jar exchgPub.jar "

+ m_inMsg.getJMSIP() + " "

+ m_inMsg.getJMSPort().ToString() + " "

+ m_inMsg.getJMSTopicName();

/**

System.Diagnostics.ProcessStartInfo psi =

new System.Diagnostics.ProcessStartInfo(pgmPath);

*/

System.Diagnostics.ProcessStartInfo psi =

new System.Diagnostics.ProcessStartInfo();

psi.WorkingDirectory = m_launchDir;

psi.FileName = "exchgPub.bat";

psi.Arguments = m_inMsg.getJMSIP() + " "

+ m_inMsg.getJMSPort().ToString() + " "

+ m_inMsg.getJMSTopicName();

psi.RedirectStandardOutput = true;

psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

psi.UseShellExecute = false;

System.Diagnostics.Process exchgPub;

try

{

exchgPub = System.Diagnostics.Process.Start(psi);

System.IO.StreamReader epubOutput = exchgPub.StandardOutput;

exchgPub.WaitForExit(2000);

if (exchgPub.HasExited)

{

String result = epubOutput.ReadToEnd();

logMessageToFile("dtiCalendarProj: replyViaPublisher() exchgPub.jar [result]" + result);

}

exchgPub.Close();

}

catch (Win32Exception w32e)

{

logMessageToFile("Could not execute: " + pgmPath);

logMessageToFile("Error was: " + w32e.Message);

}

 

So any ideas?

Thanks in advance.

-Paul


Answers (4)