Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to execute .jar file in c#

How to execute .jar file in c#

Scheduled Pinned Locked Moved C#
csharpjavatutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gresziu
    wrote on last edited by
    #1

    Hi everybody, im trying to execute a .jar file in my c# program, i have try several times and get examples, but i can't do it. I execute in the cmd, like this java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"; and this open the program. But, trying with the Process class: Process process = new Process(); System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo("java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"); process = System.Diagnostics.Process.Start(procInfo); and other instructions, i get an exception, the file can't be found. Some one knows?? Thanks in advance.

    R A 2 Replies Last reply
    0
    • G Gresziu

      Hi everybody, im trying to execute a .jar file in my c# program, i have try several times and get examples, but i can't do it. I execute in the cmd, like this java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"; and this open the program. But, trying with the Process class: Process process = new Process(); System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo("java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"); process = System.Diagnostics.Process.Start(procInfo); and other instructions, i get an exception, the file can't be found. Some one knows?? Thanks in advance.

      R Offline
      R Offline
      Ravadre
      wrote on last edited by
      #2

      If you would read the parameter's name, you would see that it's called fileName, therefore - there is no file name called "java -Xm......". Try Process proc = Process.Start("java", "-Xms60m...."); Also, make you that java exec is in your env path, otherwise supply full path to it.

      G 1 Reply Last reply
      0
      • R Ravadre

        If you would read the parameter's name, you would see that it's called fileName, therefore - there is no file name called "java -Xm......". Try Process proc = Process.Start("java", "-Xms60m...."); Also, make you that java exec is in your env path, otherwise supply full path to it.

        G Offline
        G Offline
        Gresziu
        wrote on last edited by
        #3

        Thanks for the answer dude, but it's not working still, i dont get an exception, just a ms-dos window for a second. Process proc = Process.Start("java", "java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"); proc.EnableRaisingEvents = false; proc.WaitForExit(); Have i write it correctly? I really don't understand why waitForExit is neither working..

        G 1 Reply Last reply
        0
        • G Gresziu

          Thanks for the answer dude, but it's not working still, i dont get an exception, just a ms-dos window for a second. Process proc = Process.Start("java", "java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"); proc.EnableRaisingEvents = false; proc.WaitForExit(); Have i write it correctly? I really don't understand why waitForExit is neither working..

          G Offline
          G Offline
          Gresziu
          wrote on last edited by
          #4

          FINALLY IS WORKING!!! Here is the code, thanks for ur time.. string path = "C:\\Programming"; Process process = new Process(); process.EnableRaisingEvents = false; process.StartInfo.FileName = "java.exe"; process.StartInfo.Arguments = "-jar " + '"' + path+ "\\interface.jar"; process.Start();

          1 Reply Last reply
          0
          • G Gresziu

            Hi everybody, im trying to execute a .jar file in my c# program, i have try several times and get examples, but i can't do it. I execute in the cmd, like this java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"; and this open the program. But, trying with the Process class: Process process = new Process(); System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo("java -Xms60m -Xmx256m -jar C:\\Programming\\Interface.jar"); process = System.Diagnostics.Process.Start(procInfo); and other instructions, i get an exception, the file can't be found. Some one knows?? Thanks in advance.

            A Offline
            A Offline
            A P Prajwal
            wrote on last edited by
            #5

            Hi, Use the following code to run .jar file from c# private int ExecuteProcess(string cmd, string cmdParams, string workingDirectory, int timeout, out string stdOutput) { using (Process process = Process.Start(new ProcessStartInfo(cmd, cmdParams))) { process.StartInfo.WorkingDirectory = workingDirectory; //process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); stdOutput = process.StandardOutput.ReadToEnd(); process.WaitForExit(timeout); return process.ExitCode; } } string stdOutput; string parameters = "Prajwal"; int exitCode = ExecuteProcess(@"C:\Program Files\Java\jre1.6.0\bin\Java.exe", " -jar samplejarfilename.jar " + parameters ,path, 5000, out stdOutput );

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups