无法打开Jar文件,用正确的参数VB

时间:2012-12-12 13:42:23

标签: java vb.net process

我正在制作一个游戏发射器(是的,已经有一个,但我的不同)。 问题是,如果你登录,游戏会尝试启动,但是我得到一个显示“无法访问jarfile c:\ users \ max korlaar \ dropbox \ max”的控制台窗口,它会在1毫秒后关闭。 我不知道为什么,因为我的Process Arguments中的给定jar文件就在那里,我认为VB.net对该位置做了一些事情。 jar文件位于文件夹Bin中,相对于我的程序。 (是的,我尝试用&替换+)

Dim process As New Process
Dim info As New ProcessStartInfo
info.FileName = GetJavaHome() + "\java.exe"
info.CreateNoWindow = True
info.UseShellExecute = True
info.RedirectStandardError = False
info.RedirectStandardOutput = False
Dim args As String = "-jar  -natives{1} -lwjgl{2} -mlcfg{3} -mlmod{4} -j{5} -u{6} -s{7}"
info.Arguments = String.Format(args, My.Application.Info.DirectoryPath + "\bin\natives", My.Application.Info.DirectoryPath + "\bin\natives", My.Application.Info.DirectoryPath + "\bin\lwjgl.jar", My.Application.Info.DirectoryPath + "\config\", My.Application.Info.DirectoryPath + "\mods\", My.Application.Info.DirectoryPath + "\bin\minecraft.jar\", TextBox1.Text, result)
info.Arguments = info.Arguments.Replace("\bin\minecraft.jar", My.Application.Info.DirectoryPath + "\bin\minecraft.jar")
process.StartInfo = info
process.Start()

在尝试了一些建议之后我稍微修改了一下,并得到了这个:

    Dim process As New Process
    Dim info As New ProcessStartInfo
    info.FileName = GetJavaHome() + "\java.exe"
    info.CreateNoWindow = False
    info.UseShellExecute = False
    info.RedirectStandardError = False
    info.RedirectStandardOutput = True

    'Got error: Corrupt jar file... Someone with Minecraft Experience can help me to launch it?
    Dim args As String = "-jar ""{6}"" -natives ""{1}"" -lwjgl ""{2}"" -mlcfg ""{3}"" -mlmod ""{4}"" -j ""{5}"" -u ""{6}"" -s ""{7}"""
    ' Got CMD window popping up with error and disappearing
    info.Arguments = String.Format(args, "none", My.Application.Info.DirectoryPath & "\bin\natives\", My.Application.Info.DirectoryPath & "\bin\natives", My.Application.Info.DirectoryPath & "\bin\lwjgl.jar", My.Application.Info.DirectoryPath & "\config\", My.Application.Info.DirectoryPath & "\mods\", "'" & Application.StartupPath & "\bin\minecraft.jar'", TextBox1.Text, result)
    'info.Arguments = info.Arguments.Replace("\bin\minecraft.jar", My.Application.Info.DirectoryPath + "\bin\minecraft.jar")
    process.StartInfo = info
    process.Start()

但现在我收到错误:无法访问jarfile“{path to minecraft.jar(correct path)}” 有谁知道为什么?以及如何解决这个错误?

1 个答案:

答案 0 :(得分:1)

你的路径中有一个空格,所以你必须引用它(放在两个"之间)。

Dim args As String = "-jar  -natives""{1}"" -lwjgl""{2}"" ...etc..etc..."

否则,java可执行文件将无法正确区分传递给它的参数。


如果您的路径是c:\users\max korlaar\dropbox\max & alex,并且您没有引用它,则将其作为

传递给java executale
  

java -jar c:\ users \ max korlaar \ dropbox \ max&亚历

只有c:\users\max korlaar\dropbox\max将用作java -jar的参数。

因此你必须使用引号:

  

java -jar“c:\ users \ max korlaar \ dropbox \ max& alex”