我正在尝试使用 C# 方法将 zip 文件复制到 jar 文件,如下所示:
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());
问题是我收到此错误:
错误:无法访问 jarfile example.jar
我已经确认 example.jar 和 example.zip 都存在于工作目录中,并且还编写了一个批处理文件,我可以运行该文件并创建几乎相同的 .jar 文件:
jar -cf example.jar test.zip
我能够使用此代码运行它而不会出现问题:
const string batchFile = @"C:\mydir\batJar.bat";
System.Diagnostics.Process.Start(batchFile);
我的环境变量(Windows 7)也设置正确。
最佳答案
您的批处理文件使用可执行文件“jar”,但您的 C# 程序使用可执行文件“java.exe”。
尝试:
start.FileName = "jar";
关于c# - 将文件复制到 .jar 文件会导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15534902/