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


LVL 1
mdw233Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.