-1

我正在开发一个游戏启动器(是的,已经有一个,但我的会有所不同)。问题是,如果您登录,游戏会尝试启动,但我得到一个控制台窗口,显示“无法访问 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)}” 有人知道为什么吗?以及如何解决该错误?

4

1 回答 1

1

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

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

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


如果您的路径是c:\users\max korlaar\dropbox\max & alex,并且您没有引用它,则将其传递给 java 可执行文件

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

where onlyc:\users\max korlaar\dropbox\max将用作 to 的参数java -jar

因此,您必须使用引号:

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

于 2012-12-12T13:46:54.873 回答