Skip to content

Commit

Permalink
更新build.py,生成完整的jre
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxuqaq committed Feb 2, 2023
1 parent ed883d5 commit 4b658ff
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ def getFileMd5(file_name):
print("JAVA_HOME set to " + jdkPath)

# 编译jar
os.system('set JAVA_HOME=' + jdkPath + '&& mvn clean compile package')
if os.system('set JAVA_HOME=' + jdkPath + '&& mvn clean compile package') != 0:
print('maven compile failed')
exit()
# 获取版本
configs = jproperties.Properties()
with open(r'.\target\maven-archiver\pom.properties', 'rb') as f:
Expand All @@ -140,18 +142,33 @@ def getFileMd5(file_name):
# 切换到build
os.chdir(buildDir)

os.system(r'xcopy ..\target\File-Engine.jar . /Y')
if os.system(r'xcopy ..\target\File-Engine.jar . /Y') != 0:
print('xcopy File-Engine.jar failed.')
exit()
os.system(r'del /Q /F File-Engine.zip')

# 生成jre
# binPath = os.path.join(jdkPath, 'bin')
# jdepExe = os.path.join(binPath, 'jdeps.exe')
# deps = subprocess.check_output([jdepExe, '--ignore-missing-deps', '--print-module-deps', r'..\target\File-Engine-' + fileEngineVersion.data + '.jar'])
# depsStr = deps.decode().strip()
binPath = os.path.join(jdkPath, 'bin')
jdepExe = os.path.join(binPath, 'jdeps.exe')
deps = subprocess.check_output([jdepExe, '--ignore-missing-deps', '--print-module-deps', r'..\target\File-Engine-' + fileEngineVersion.data + '.jar'])
depsStr = deps.decode().strip()
javaExe = os.path.join(binPath, 'java.exe')
modules = subprocess.check_output([javaExe, '--list-modules'])
modulesStr = modules.decode().strip()
tmpModuleList = modulesStr.splitlines()
moduleList = []
for each in tmpModuleList:
if not each.startswith('jdk.') and each.startswith('java.'):
moduleName = each.split('@')
moduleList.append(moduleName[0])
depsStr = ','.join(moduleList)
shutil.rmtree('jre')
jlinkExe = os.path.join(binPath, 'jlink.exe')
jlinkExe = jlinkExe[0:1] + '\"' + jlinkExe[1:] + '\"'
os.system(jlinkExe + r' --no-header-files --no-man-pages --compress=2 --module-path jmods --add-modules ' + depsStr + ' --output jre')
if os.system(jlinkExe + r' --no-header-files --no-man-pages --compress=2 --module-path jmods --add-modules ' + depsStr + ' --output jre') != 0:
print('Generate jre failed.')
exit()

# 精简jar
delFileInZip()
Expand Down Expand Up @@ -181,7 +198,9 @@ def getFileMd5(file_name):
with zipfile.ZipFile('File-Engine.zip', mode="a") as f:
f.write('File-Engine.jar')

os.system(r'xcopy File-Engine.zip "..\C++\launcherWrap\launcherWrap\" /Y')
if os.system(r'xcopy File-Engine.zip "..\C++\launcherWrap\launcherWrap\" /Y') != 0:
print('xcopy File-Engine.zip to launcherWrap directory failed.')
exit()

# 编译启动器
vsPathList = vswhere.find(
Expand Down

0 comments on commit 4b658ff

Please sign in to comment.