Java 如何从 C# 代码中运行 jar 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23753060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 01:01:33  来源:igfitidea点击:

How to run jar file form C# code

c#java

提问by Planet-Zoom

I am new to C#and tying to run jar file from C# code. But it seems that jar file is not opening and command prompt disappers very quicky as I am unable to see any error messgage.

我是新手C#并打算从 C# 代码运行 jar 文件。但似乎 jar 文件没有打开,命令提示符很快消失,因为我看不到任何错误消息。

Here is my code ,

这是我的代码,

myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = "java";
myProcess.StartInfo.Arguments = "D:\DATA\PROJECT\LicensingManagement\Assignment\JavaLogin.jar";
myProcess.Start();

Can any one put me in right direction ? Whats wrong I am doing here ?

任何人都可以让我朝着正确的方向发展吗?我在这里做什么错了?

采纳答案by jatanp

You will have to provide -jar switch to java command.

您必须将 -jar 开关提供给 java 命令。

For example, the command to execute JAR file is,

例如,执行 JAR 文件的命令是,

java -jar D:\DATA\PROJECT\LicensingManagement\Assignment\JavaLogin.jar

So you may try,

所以你可以试试,

myProcess.StartInfo.Arguments = "-jar D:\DATA\PROJECT\LicensingManagement\Assignment\JavaLogin.jar";