Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2659
  • Last Modified:

Run a .JAR file from C#

Hi All,
Hi All,

I have a java program that I have complied into a .JAR file.  It accepts 2 string arguments.  I am able to run it from the CDM window by typing the following command:
java -jar c:\temp\Monitor.JAR "arg1" "arg2"

How can I do this same exact thing from C#?
I have tried Process.Start("java -jar c:\\temp\\Monitor.JAR \"arg1\" \"arg2\"
"); but I get a message "The system cannot find the file specified".

As always, thanks in advance for any help!!
-Matt



I have a java program that I have complied into a .JAR file.  It accepts 2 string arguments.  I am able to run it from the CDM window with no problem by tyoing the following command:
java -jar c:\temp\Monitor.JAR "arg1" "arg2"

How can I do this same exact thing from C#?
I have tried Process.Start("java -jar c:\\temp\\Monitor.JAR \"arg1\" \"arg2\"
"); but I get a message "The system cannot find the file specified".

As always, thanks in advance for any help!!
-Matt


0
mdw233
Asked:
mdw233
  • 2
  • 2
1 Solution
 
Anurag ThakurTechnical ManagerCommented:
can you specify the complete path of the java.exe instead of just java and arguments and try again
0
 
David H.H.LeeCommented:
Hi mdw233,
Perhaps you can use "StartInfo" to accept the arguments. You can amend it accordingly.
eg:
Process test= new Process();

test.StartInfo.FileName = @"C:/Java/jdk/jre/bin/java.exe";
test.StartInfo.Arguments = "java -jar c:\temp\Monitor.JAR " & arg1 & " " & arg2 & " ";
test.Start();

0
 
David H.H.LeeCommented:
Hi mdw233,
You can refer following link for more details regarding mentioned:
http://www.coderjournal.com/2008/05/how-to-create-a-yui-compressor-msbuild-task/
0
 
Anurag ThakurTechnical ManagerCommented:
another method of how to run the JAR file and get back the return value/code
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3413988&SiteID=1
0
 
mdw233Author Commented:
Hey x_com,

That seemed to work fine with 1 edit:
I changed
test.StartInfo.Arguments = "java -jar c:\temp\Monitor.JAR " & arg1 & " " & arg2 & " ";
to
test.StartInfo.Arguments = "-jar c:\temp\Monitor.JAR " & arg1 & " " & arg2 & " ";

and it worked perfectly!!

Thanks you so much for the help!!

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now