[英]Launching JAR with Process.Start: javaw.exe runs but “nothing happens”?
鉴于代码。 当点击按钮时没有任何反应,我在visual studio中没有得到调试消息等。 但是,如果我要双击其文件夹中的.jar文件,我可以运行它。 任何人都知道为什么? 单击按钮时查看任务管理器。 javaw.exe已创建但没有任何反应。
private void btnKinderPuzzle_Click(object sender, RoutedEventArgs e)
{
// Check if this program is opened
if (IsProcessOpen("MTPuzzle"))
{
MessageBox.Show("KinderPuzzle is already running", "Kinder Package", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
Process.Start(Directory.GetCurrentDirectory() + "\\Puzzle\\PuzzleGame\\MTPuzzle.jar");
}
}
Process.Start("java.exe",
Path.Combine("-jar " + Directory.GetCurrentDirectory(),
"Puzzle\\PuzzleGame\\MTPuzzle.jar"));
路径可能不正确。 你可以改用
Process.Start(Path.Combine(Directory.GetCurrentDirectory(), "Puzzle\\PuzzleGame\\MTPuzzle.jar"));
如果仍然是,那么我认为Java设置中的问题。 要解决此潜在问题,请在jar
文件附近创建一个文件run.cmd
并将此代码写入:
java -jar "MTPuzzle.jar"
然后,使用Process.Start
启动文件run.cmd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.