我在使用ant工具构建时遇到错误
installer.izpack.exe:
[exec] Traceback (most recent call last):
[exec] File "C:\PROGRA~1\IzPack/utils/wrappers/izpack2exe/izpack2exe.py", line 126, in <module>
[exec] main()
[exec] File "C:\PROGRA~1\IzPack/utils/wrappers/izpack2exe/izpack2exe.py", line 123, in main
[exec] create_exe(parse_options())
[exec] File "C:\PROGRA~1\IzPack/utils/wrappers/izpack2exe/izpack2exe.py", line 77, in create_exe
[exec] subprocess.call(p7zcmd, shell=use_shell)
[exec] File "C:\Python27\lib\subprocess.py", line 493, in call
[exec] return Popen(*popenargs, **kwargs).wait()
[exec] File "C:\Python27\lib\subprocess.py", line 679, in __init__
[exec] errread, errwrite)
[exec] File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
[exec] startupinfo)
[exec] WindowsError: [Error 193] %1 is not a valid Win32 application
BUILD FAILED
E:\Java Projects\Spark Projects\EastIT - Copy\build\build.xml:873: exec returned: 1
以下是获取错误的代码。
<target name="installer.izpack.exe" depends="installer.izpack" description="build release executable izpack installer">
<exec executable="python" failonerror="true">
<arg line="${installer.izpack.dir}/utils/wrappers/izpack2exe/izpack2exe.py"/>
<arg line="--file=${basedir}/installer/EasyIT-installer.jar"/>
<arg line="--output=${basedir}/installer/EasyIT-installer.exe"/>
<arg line="--no-upx"/>
</exec>
</target>
请有人知道如何解决这个问题吗?
答案 0 :(得分:2)
我在Windows 7 x64计算机上手动运行izpack2exe.py脚本时遇到同样的问题。我对python脚本做了一些调整,现在看起来如下:
import os
import sys
import subprocess
import shutil
import optparse
import shlex
def parse_options():
parser = optparse.OptionParser()
parser.add_option("--file", action="append", dest="file",
help="The installer JAR file / files")
parser.add_option("--output", action="store", dest="output",
default="setup.exe",
help="The executable file")
parser.add_option("--with-jdk", action="store", dest="with_jre", default="",
help="The bundled JRE to run the exe independently of the system resources. ") # choosen JDK that may came with the package
parser.add_option("--with-7z", action="store", dest="p7z",
default="7za",
help="Path to the 7-Zip executable")
parser.add_option("--with-upx", action="store", dest="upx",
default="upx",
help="Path to the UPX executable")
parser.add_option("--no-upx", action="store_true", dest="no_upx",
default=False,
help="Do not use UPX to further compress the output")
parser.add_option("--launch-file", action="store", dest="launch",
default="",
help="File to launch after extract")
parser.add_option("--launch-args", action="store", dest="launchargs",
default="",
help="Arguments for file to launch after extract")
parser.add_option("--name", action="store", dest="name",
default="IzPack",
help="Name of package for title bar and prompts")
parser.add_option("--prompt", action="store_true", dest="prompt",
default=False,
help="Prompt the user before extraction?")
(options, args) = parser.parse_args()
if (options.file is None):
parser.error("no installer file has been given")
return options
def create_exe(settings):
if len(settings.file) > 0:
filename = os.path.basename(settings.file[0])
else:
filename = ''
if len(settings.with_jre) > 0:
jdk = os.path.basename(settings.with_jre) #inside the jdk/jre that was given, there must be a bin/java.exe file
jdk = jdk + "\\bin\\javaw.exe"
print(jdk)
settings.file.append(settings.with_jre) #jdk/jre is going in the package
else:
jdk = 'javaw' #java is added somehow to the PATH
if settings.p7z == '7za':
p7z = os.path.join(os.path.dirname(sys.argv[0]), '7za')
else:
p7z = settings.p7z
# really no need right now
# use_shell = sys.platform != 'win32'
if (os.access('installer.7z', os.F_OK)):
os.remove('installer.7z')
files = '" "'.join(settings.file)
p7zcmd = '7za.exe a -mmt -t7z -mx=9 installer.7z "%s"' % files
zip_proc = subprocess.Popen(shlex.split(p7zcmd))
zip_proc.communicate()
config = open('config.txt', 'w')
config.write(';!@Install@!UTF-8!\n')
config.write('Title="%s"\n' % settings.name)
if settings.prompt:
config.write('BeginPrompt="Install %s?"\n' % settings.name)
config.write('Progress="yes"\n')
if settings.launch == '':
config.write('ExecuteFile="' + jdk + '"\n') # who is going to run my installer.jar?
config.write('ExecuteParameters="-jar \\\"%s\\\"' % filename)
if settings.launchargs != '':
config.write(' %s"\n' % settings.launchargs)
else:
config.write('"\n')
else:
config.write('ExecuteFile="%s"\n' % settings.launch)
if settings.launchargs != '':
config.write('ExecuteParameters="%s"\n' % settings.launchargs)
config.write(';!@InstallEnd@!\n')
config.close()
sfx = os.path.join(os.path.dirname(p7z), '7zS.sfx')
files = [sfx, 'config.txt', 'installer.7z']
output = open(settings.output, 'wb')
for f in files:
in_file = open(f, 'rb')
shutil.copyfileobj(in_file, output, 2048)
in_file.close()
output.close()
if (not settings.no_upx):
if settings.upx == 'upx':
upx = os.path.join(os.path.dirname(sys.argv[0]), 'upx')
else:
upx = settings.upx
upx = 'upx.exe --ultra-brute "%s"' % settings.output
upx_proc = subprocess.Popen(shlex.split(upx))
upx_proc.communicate()
os.remove('config.txt')
os.remove('installer.7z')
def main():
create_exe(parse_options())
if __name__ == "__main__":
main()
我静静地将7za.exe放在p7zcmd变量中,这不会导致问题,因为它在我的路径上。我阻止了脚本执行,直到子进程完成(分别为7zip和upx)解决了我的问题。
希望我能帮助你。
此致