【发布时间】:2019-05-17 12:55:11
【问题描述】:
我正在将 Java 程序安装为带有捆绑 JRE 文件夹的 exe。我无法通过我的应用程序成功调用捆绑的java.exe。
所以我的笔记本电脑已经安装了 Java,所以以下工作正常:
[Files]
Source: "jre\*"; DestDir: "{app}\jre"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "build\launch4j\Application Lite.exe"; DestDir: "{app}"; Flags: ignoreversion; \
AfterInstall: MyAfterInstall
[Code]
procedure MyAfterInstall();
var ResultCode: Integer;
begin
Exec(
'cmd.exe',
'/c java -cp ' + AddQuotes(ExpandConstant('{app}\Application Lite.exe')) +
' com.examplesoftware.applicationlite.support.hibernateSupport',
'', SW_SHOW, ewWaitUntilTerminated, ResultCode);
end;
其中{app} 默认为c:\Example Software\Application Lite。
当我尝试使用捆绑的 JRE 时,以下内容不起作用:
[Code]
procedure MyAfterInstall();
var ResultCode: Integer;
begin
Exec(
'cmd.exe',
'/k ' + AddQuotes(ExpandConstant('{app}\jre\bin\java.exe')) +
' -cp ' + AddQuotes(ExpandConstant('{app}\Application Lite.exe')) +
' com.examplesoftware.applicationlite.support.hibernateSupport',
'', SW_SHOW, ewWaitUntilTerminated, ResultCode);
end;
我得到错误:
'c:\Example' 未被识别为内部或外部命令, 可运行的程序或批处理文件。
如果我将echo 与这样的代码一起使用:
Exec(
'cmd.exe',
'/k echo ' + AddQuotes(ExpandConstant('{app}\jre\bin\java.exe')) +
' -cp ' + AddQuotes(ExpandConstant('{app}\Application Lite.exe')) +
' com.examplesoftware.applicationlite.support.hibernateSupport',
'', SW_SHOW, ewWaitUntilTerminated, ResultCode);
并复制它工作的命令。我不明白它为什么会坏。
【问题讨论】:
-
你试过简单的
Exec(ExpandConstant('{app}\jre\bin\java.exe'), ' -cp ' + AddQuotes(ExpandConstant('{app}\Application Lite.exe')) + ' com.examplesoftware.applicationlite.support.hibernateSupport', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)吗? -
虽然你确定
{app}\Application Lite.exe是正确的搜索路径?不应该只是{app}? -
@MartinPrikryl 好吧,“Application Lite.exe”是一个包装好的 jar,里面有一个支持类,当调用它时,它会在 MySQL 中创建必要的表。如果我运行
Exec('cmd.exe', '/k echo ...'我得到: "c:\Example Software\Application Lite\jre\bin\java.exe" -cp "c:\Example Software\Application Lite\Application Lite.exe" com.examplesoftware .applicationlite.support.hibernateSupport 如果我将它复制粘贴到 cmd 中,它就可以工作了。 -
或者,在
/k(/c) 之后为整个命令加上另一对引号,例如:Exec('cmd.exe', '/k "' + AddQuotes(ExpandConstant('{app}\jre\bin\java.exe')) + ' -cp ' + AddQuotes(ExpandConstant('{app}\Application Lite.exe')) + ' com.examplesoftware.applicationlite.support.hibernateSupport"', '', SW_SHOW, ewWaitUntilTerminated, ResultCode); -
但是即使使用
Exec(ExpandConstant('{app}\jre\bin\java.exe'), '-cp ' + AddQuotes(ExpandConstant('{app}\Application Lite.exe')) + ' com.examplesoftware.applicationlite.support.hibernateSupport', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)也应该可以工作
标签: java cmd inno-setup pascalscript