如何使用Pyinstaller捆绑.jar文件 [英] How To Bundle .jar Files with Pyinstaller
问题描述
如何将 pyinstaller 捆绑为.jar文件作为使用它们的python项目的档案?
How do you get pyinstaller to bundle .jar files as archives for a python project that utilizes them?
例如,制作一个exe(我正在使用 pyjnius 用于处理 sikuli-standalone jar ):
For instance, to make an exe with (I am using pyjnius for handling the sikuli-standalone jar):
# test.py
import os
import sys
# set the classpath so java can find the code I want to work with
sikuli_jar = '/sikuli-api.standalone-1.0.3-Pre-1.jar'
jarpath = os.path.dirname(os.path.realpath(__file__)) + sikuli_jar
os.environ['CLASSPATH'] = jarpath
# now load a java class
from jnius import autoclass
API = autoclass('org.sikuli.api.API')
Pyisntaller创建(一个文件夹)exe with:
Pyisntaller creates the (one folder) exe with:
pyinstaller -d test.py
但据我所知,jar不是捆绑的,并且exe 无法访问,除非你手动将它放在Pyinstaller生成的文件夹中
But the jar to the best of my knowledge is not bundled and is inaccessible to the exe unless you manually place it in the folder generated by Pyinstaller
根据 Pyinstaller手册:
CArchive包含你想要的东西。它非常像bz文件那样是
。
"CArchive contains whatever you want to stuff into it. It's very much like a .zip file."
然后我尝试编辑以前自动生成的 test.spec
文件包含:
I then try editing the previously auto-generated test.spec
file with:
jar = 'sikuli-api.standalone-1.0.3-Pre-1.jar'
jar_path = 'C:\\Python27\\Lib\\site-packages\\sikuli-0.1-py2.7.egg\\sikuli\\' + jar
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
[('sikulijar', jar_path, 'PKG')],
strip=None,
upx=True,
name='test')
我尝试使用以下规范构建基于此规范文件的exe:
And I try building the exe based on this spec file with:
python C:\workspace\code\PyInstaller-2.1\PyInstaller\build.py --onefile test.spec
但没有任何反应并且没有错误返回。有人可以提供简单的一步一步的教程如何做到这一点?非常感谢!
But nothing happens and no error returns. Can someone provide a simple step by step tutorial how this could be done? Many thanks!
推荐答案
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
[('sikulijar', jar_path, 'PKG')],
strip=None,
upx=True,
name='test')
将元组中的'sikulijar'更改为 jar (您已定义的变量)。你需要引用你在代码中使用的相同名称。
change 'sikulijar' in the tuple to just jar (the variable that you have already defined). you need to reference the same name that you have used in code.
但是,我仍然试图让JVM正确初始化。如果我弄明白的话,我会张贴。
However, I'm still trying to get the JVM to initialize properly. I'll post that if I figure that out.
这篇关于如何使用Pyinstaller捆绑.jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!