Loading Java JAR through c#

This is a discussion on Loading Java JAR through c# within the C# Programming forums, part of the General Programming Boards category; I've made a program that will attempt to open a JAR file by clicking a button in my c# program, ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Loading Java JAR through c#

    I've made a program that will attempt to open a JAR file by clicking a button in my c# program, unfortunately it won't work.

    Here's the code:

    Code:
    string stdOutput;
    	int exitCode = ExecuteProcess( @"\"C:\Program Files\Java\jre1.6.0\bin\Java.exe\""
      , " -jar myJar.jar "
      , @"\"C:\Client\Run.jar""
      , myTimeout
      , out stdOutput );
    The above didn't work, so I tried a different method and replaced with:

    Code:
    System.Diagnostics.Process.Start(@"c:/Client\Run.jar");
    Yet I failed, any suggestions?

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,205
    Have you tried something like this?
    Code:
    Process java = new Process();
    java.StartInfo.FileName = pathToJava_exe;
    java.StartInfo.Arguments = "-jar \"" + pathToJarFile + "\" " + otherArgs;
    java.Start();
    Process is part of System.Diagnostics namespace. Also I like to substitute all \ with / in any paths I give to different processes. This eases things up with escaping and whatnot.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    1
    It should be like below

    Code:
    System.Diagnostics.Process.Start(@"c:\Client\Run.jar");

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Quote Originally Posted by kayC++ View Post
    It should be like below

    Code:
    System.Diagnostics.Process.Start(@"c:\Client\Run.jar");
    1) That doesn't pass the command line arguments required.
    2) You're responding to an old thread.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cargo loading system
    By kyle rull in forum C Programming
    Replies: 1
    Last Post: 04-20-2009, 12:16 PM
  2. Java: Packaging Self-running Jar
    By alphaoide in forum Tech Board
    Replies: 1
    Last Post: 06-29-2005, 10:31 PM
  3. C#, Java, C++
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-05-2004, 02:06 PM
  4. The Java language is being expanded
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 06-11-2004, 09:07 PM
  5. Java woes
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 07-06-2003, 12:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21