Java 无法打开具有正确参数的Jar文件

Java 无法打开具有正确参数的Jar文件,java,vb.net,process,Java,Vb.net,Process,我正在开发一款游戏发射器(是的,已经有了,但我的将有所不同)。 问题是,如果您登录,游戏会尝试启动,但我看到一个控制台窗口显示“无法访问jarfile c:\users\max korlaar\dropbox\max”,它会在1毫秒后关闭。 我不知道为什么,因为我的进程参数中给定的jar文件就在那里,而且我认为VB.net对这个位置做了一些事情。jar文件位于相对于我的程序的文件夹箱中。(是的,我试着用&)替换+) 在尝试了一些建议后,我对其进行了一些修改,得到了以下结果: Dim pr

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

在尝试了一些建议后,我对其进行了一些修改,得到了以下结果:

    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()
但是现在我得到了错误:无法访问jar文件“{path to minecraft.jar(correct path)}”
有人知道为什么吗?如何修复该错误?

您的路径中有一个空格,因此必须引用它(放在两个
之间)

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


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

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

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

因此,您必须使用引号:

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


“我的会有所不同“除了您的命令不起作用之外,还有什么区别?您是否尝试过使用应用程序中使用的相同命令从应用程序路径的命令窗口启动
jar
文件?是的,问题是我在jar文件路径前后添加了一个'。但是现在我发现了一个很长的错误,比如“找不到类”,或者类似的东西——也许有Minecraft经验的人知道是的,但问题是,该文件与我的程序有关。该文件位于“我的程序”的位置,在“我的程序”旁边的文件夹中。那我该怎么做呢?我已经在每个{#}的后面加上了“”。现在我已经更改了代码,但出现了一个错误:无法访问jarfile{correct path to minecraft.jar}。(也是在一个快速消失的控制台窗口中。(请参阅问题中的代码更改)此问题已得到回答。谢谢。现在我有另一个问题,但我将在另一个问题中提出此问题
    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()
Dim args As String = "-jar  -natives""{1}"" -lwjgl""{2}"" ...etc..etc..."