none
Error: Unable To Access Jar File

    Question

  • I am attempting to copy a zip file to a jar file in a C# method like this:

        ProcessStartInfo start = new ProcessStartInfo();
        start.FileName = "java.exe";
        start.WorkingDirectory = @"C:\mydir\";
        start.Arguments = @" -jar example.jar example.zip";
        Process java = new Process();
        java.StartInfo = start;
        java.Start();
    
        var stdOut = java.StandardOutput.ReadToEnd();
        java.WaitForExit();
        Console.WriteLine(java.ExitCode.ToString());
        

    The problem is that I am receiving this error:
    Error: Unable to access jarfile example.jar

    I've confirmed that both example.jar and example.zip exist in the Working Directory and have also written a batch file that I can run and create a .jar file that is almost identical:

    jar -cf example.jar test.zip

    I was able to run this without issue with this code:

    const string batchFile = @"C:\mydir\batJar.bat";
        System.Diagnostics.Process.Start(batchFile);

    My environment variables are also set up properly.

    Thanks

    Wednesday, March 20, 2013 9:20 PM

Answers

All replies

  • Why do you think your question is related to C#? Does your batches work when invoked directly? Do you receive an error - what ever this is - or do you receive an Exception? If so, where does the exception occur?
    Wednesday, March 20, 2013 9:59 PM
  • Hi,

    please check what you are doing!

    java -jar jarfile arguments
    => this starts an existing jar file and arguments are arguments to the command.

    jar -cf newfile content
    => this creates a new jar file and simply puts content inside.

    But what do you want to get? You have an zip file and you want a jar file? jar files are a ZIP file. Just rename them. (http://en.wikipedia.org/wiki/JAR_(file_format)

    With kind regards,

    Konrad


    Thursday, March 21, 2013 1:18 PM