Spark源代码编译生成错误解决方案

缘由

最近项目需要对Spark进行二次开发,在对Spark二次开发完成之后,需要对其进行打包成exe文件的操作。互联网真是一个宝贵的知识库,千辛万苦之下找到了Spark开发记录(windows环境)和install4j打包Spark详解,前者介绍了两种版本spark的打包方式,而后者的打包方式适用于较早的2.5.x版本的Spark,对于2.6.x版本的Spark可以按照第一篇文章介绍的内容进行打包操作。但是按照操作进行下去之后发现项目无法ant打包成功。错误代码如下:

错误代码

exe:
 [launch4j] Compiling resources
 [launch4j] Linking
 [launch4j] Wrapping
 [launch4j] Successfully created D:\javaee_workspace\spark\target\build\Spark.exe
 [launch4j] Compiling resources
 [launch4j] Linking
 [launch4j] Successfully created D:\javaee_workspace\spark\target\build\starter.exe
installer.izpack:
   [IzPack] Building installer jar: D:\javaee_workspace\spark\installer\spark-installer.jar
   [IzPack] Copying 61 files into installer
   [IzPack] Merging 8 jars into installer
   [IzPack] Writing 1 Pack into installer
installer.izpack.exe:
     [exec] Traceback (most recent call last):
     [exec]   File "c:/IzPack/utils/wrappers/izpack2exe/izpack2exe.py", line 126, in <module>
     [exec]     main()
     [exec]   File "c:/IzPack/utils/wrappers/izpack2exe/izpack2exe.py", line 123, in main
     [exec]     create_exe(parse_options())
     [exec]   File "c:/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 524, in call
     [exec]     return Popen(*popenargs, **kwargs).wait()
     [exec]   File "C:\Python27\lib\subprocess.py", line 711, in __init__
     [exec]     errread, errwrite)
     [exec]   File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
     [exec]     startupinfo)
     [exec] WindowsError: [Error 193] %1 不是有效的 Win32

BUILD FAILED
D:\javaee_workspace\spark\build\build.xml:876: exec returned: 1

解决方案

于是上网上搜索,在Openfire的官方网站上有人提出了这个问题“failing python script while creating installer using Izpack for spark 2.6.3”,但是没有人回答,于是又在浩大的网络上寻找答案,但是最终还是没有找到。

在查找关于python的相关内容时,找到了Problems using subprocess.call() in Python 2.7.2 on Windows这个帖子,虽然内容不一样,但是引起的Python的错误是一样的,其解决方案是:

subprocess.call('dir', shell=True)
于是,找到了C:\IzPack\utils\wrappers\izpack2exe下的izpack2exe.py文件,找到调用subprocess.call('dir', shell=True)的代码如下:

use_shell = sys.platform != 'win32'
    
    if (os.access('installer.7z', os.F_OK)):
        os.remove('installer.7z')
    files = '" "'.join(settings.file)
    p7zcmd = '"%s" a -mmt -t7z -mx=9 installer.7z "%s"' % (p7z, files)
    subprocess.call(p7zcmd, shell=use_shell)
将其

subprocess.call(p7zcmd, shell=use_shell)
替换为
subprocess.call(p7zcmd, shell=True)
程序再次点击ant运行installer.izpack.exe打包程序,执行打包出spark-installer.exe文件。

你可能感兴趣的:(Spark源代码编译生成错误解决方案)