-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.bat
More file actions
306 lines (278 loc) · 11 KB
/
package.bat
File metadata and controls
306 lines (278 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
@echo off
setlocal ENABLEDELAYEDEXPANSION
if not defined JDK_PATH (
if defined JAVA_HOME (
set "JDK_PATH=%JAVA_HOME%"
) else (
set "JDK_PATH=C:\Program Files\Java\jdk-17"
)
)
set "JPACKAGE=%JDK_PATH%\bin\jpackage.exe"
if not exist "%JPACKAGE%" (
pause
exit /b 1
)
set "VERFILE=%TEMP%\fc_java_ver.txt"
if exist "%VERFILE%" del /f /q "%VERFILE%" >nul 2>&1
cmd /c ""%JDK_PATH%\bin\java.exe" -version 2^>^&1 | findstr /i "version" > "%VERFILE%""
if not exist "%VERFILE%" (
pause
exit /b 1
)
set "JAVA_VER="
for /f "tokens=3" %%v in ('type "%VERFILE%" ^| findstr /i "version"') do set "JAVA_VER=%%~v"
for /f "tokens=1 delims=." %%m in ("!JAVA_VER!") do set "JAVA_MAJOR=%%m"
del /f /q "%VERFILE%" >nul 2>&1
set "BEST_SDK="
set "BEST_MAJOR=0"
for /f "delims=" %%D in ('dir /b /ad "javafx-backup" 2^>nul') do (
echo %%D | findstr /b /c:"javafx-sdk-" >nul || (rem not a javafx-sdk folder, skip)
echo %%D | findstr /b /c:"javafx-sdk-" >nul && (
for /f "tokens=3 delims=-" %%P in ("%%D") do (
for /f "tokens=1 delims=." %%Q in ("%%P") do (
set "CAND_MAJOR=%%Q"
if exist "javafx-backup\%%D\lib" (
if defined JAVA_MAJOR (
if !CAND_MAJOR! LEQ !JAVA_MAJOR! (
if !CAND_MAJOR! GTR !BEST_MAJOR! (
set "BEST_MAJOR=!CAND_MAJOR!"
set "BEST_SDK=javafx-backup\%%D\lib"
)
)
) else (
if !CAND_MAJOR! GTR !BEST_MAJOR! (
set "BEST_MAJOR=!CAND_MAJOR!"
set "BEST_SDK=javafx-backup\%%D\lib"
)
)
)
)
)
)
)
if defined BEST_SDK (
set "JAVAFX_REL=!BEST_SDK!"
)
else (
if exist "javafx-backup\javafx-sdk-17.0.17\lib" (
set "JAVAFX_REL=javafx-backup\javafx-sdk-17.0.17\lib"
) else (
pause
exit /b 1
)
)
rem Compute JavaFX native (bin) folder from selected lib path
set "JAVAFX_BIN=%JAVAFX_REL:\lib=\bin%"
echo JavaFX native folder: %JAVAFX_BIN%
if not exist app.jar (
pause
exit /b 1
)
set "DEST=dist"
if not exist "%DEST%" mkdir "%DEST%"
set "JPACKAGE_TYPE=app-image"
where light.exe >nul 2>&1 && set "JPACKAGE_TYPE=exe"
rem Remove previous app image folder if it exists to avoid jpackage error
if exist "%DEST%\Flashcards" rmdir /s /q "%DEST%\Flashcards"
rem Diagnostic output
echo.
echo == Packaging diagnostic ==
echo JDK_PATH=%JDK_PATH%
echo JPACKAGE=%JPACKAGE%
echo JAVA_VER=%JAVA_VER%
echo JAVA_MAJOR=%JAVA_MAJOR%
echo JAVAFX_REL=%JAVAFX_REL%
echo JPACKAGE_TYPE=%JPACKAGE_TYPE%
if exist app.jar (echo app.jar exists) else (echo app.jar MISSING)
echo Dest folder: %DEST%
echo ============================
echo Running jpackage...
rem Prepare temporary resource directory to ensure styles, sounds, fonts are included
set "RES_DIR=package-resources"
if exist "%RES_DIR%" rmdir /s /q "%RES_DIR%"
mkdir "%RES_DIR%"
if exist "styles.css" copy /y "styles.css" "%RES_DIR%\styles.css" >nul 2>&1
if exist "sounds" xcopy "sounds" "%RES_DIR%\sounds" /E /I /Y >nul 2>&1
if exist "fonts" xcopy "fonts" "%RES_DIR%\fonts" /E /I /Y >nul 2>&1
rem Create a minimal input folder for jpackage containing only the application jar
set "INPUT_DIR=%TEMP%\fc-input"
if exist "%INPUT_DIR%" rmdir /s /q "%INPUT_DIR%"
mkdir "%INPUT_DIR%"
copy /y "app.jar" "%INPUT_DIR%\" >nul 2>&1
rem Run jpackage directly and capture verbose output to a log for troubleshooting
echo Running jpackage (this may take a while) - logging to %TEMP%\jpackage.log
rem "%JPACKAGE%" --type %JPACKAGE_TYPE% --name Flashcards --app-version 1.0.0 --dest "%DEST%" --input "%INPUT_DIR%" --resource-dir "%CD%\%RES_DIR%" --main-jar app.jar --main-class Main --module-path "%CD%\%JAVAFX_REL%" --add-modules javafx.controls,javafx.fxml,javafx.media --java-options "--enable-native-access=javafx.graphics" --java-options "--enable-native-access=javafx.media" --java-options "-Dprism.order=sw" --java-options "-Dprism.forceGPU=false" --java-options "-Dprism.verbose=true" --java-options "-Djava.library.path=%CD%\%JAVAFX_BIN%" --win-console --verbose > "%TEMP%\jpackage.log" 2>&1
"%JPACKAGE%" --type %JPACKAGE_TYPE% --name Flashcards --app-version 1.0.0 --dest "%DEST%" --input "%INPUT_DIR%" --resource-dir "%CD%\%RES_DIR%" --main-jar app.jar --main-class Main --module-path "%CD%\%JAVAFX_REL%" --add-modules javafx.controls,javafx.fxml,javafx.media --java-options "--enable-native-access=javafx.graphics" --java-options "--enable-native-access=javafx.media" --java-options "-Dprism.order=sw" --java-options "-Dprism.forceGPU=false" --java-options "-Dprism.verbose=true" --java-options "-Djava.library.path=%CD%\%JAVAFX_BIN%" --verbose > "%TEMP%\jpackage.log" 2>&1
rem Clean up temporary input and resource dirs
if exist "%INPUT_DIR%" rmdir /s /q "%INPUT_DIR%"
if exist "%RES_DIR%" rmdir /s /q "%RES_DIR%"
if errorlevel 1 (
echo jpackage failed -- see %TEMP%\jpackage.log for details
type "%TEMP%\jpackage.log"
pause
exit /b 1
)
if "%JPACKAGE_TYPE%"=="app-image" (
echo Built app image in %DEST%\Flashcards. Run %DEST%\Flashcards\Flashcards.exe
) else (
echo Built installer in %DEST%. Run the installer to install Flashcards.
)
rem Determine actual image directory created by jpackage (robust lookup)
set "IMAGE_DIR="
if exist "%DEST%\Flashcards" (
set "IMAGE_DIR=%DEST%\Flashcards"
) else (
for /f "delims=" %%I in ('dir "%DEST%\Flashcards*" /b /ad 2^>nul') do (
set "IMAGE_DIR=%DEST%\%%I"
goto :_found_image_dir
)
)
:_found_image_dir
if not defined IMAGE_DIR (
echo WARNING: Could not find app image directory under %DEST%. Skipping resource copy.
) else (
echo Found image directory: %IMAGE_DIR%
rem Prefer robocopy if available (more reliable). Use quiet output switches.
where robocopy >nul 2>&1
if errorlevel 1 (
set "USE_ROBOCOPY=0"
) else (
set "USE_ROBOCOPY=1"
)
rem Copy styles.css
if exist "styles.css" (
if "%USE_ROBOCOPY%"=="1" (
robocopy . "%IMAGE_DIR%" "styles.css" /NFL /NDL /NJH /NJS >nul
) else (
copy /y "styles.css" "%IMAGE_DIR%\styles.css" >nul 2>&1
)
)
rem Copy sounds dir
if exist "sounds" (
if "%USE_ROBOCOPY%"=="1" (
robocopy "sounds" "%IMAGE_DIR%\sounds" * /E /NFL /NDL /NJH /NJS >nul
) else (
xcopy "sounds" "%IMAGE_DIR%\sounds" /E /I /Y >nul 2>&1
)
)
rem Copy fonts dir
if exist "fonts" (
if "%USE_ROBOCOPY%"=="1" (
robocopy "fonts" "%IMAGE_DIR%\fonts" * /E /NFL /NDL /NJH /NJS >nul
) else (
xcopy "fonts" "%IMAGE_DIR%\fonts" /E /I /Y >nul 2>&1
)
)
echo Copied styles/sounds/fonts into %IMAGE_DIR%
rem Also copy into the app subfolder if present
if exist "%IMAGE_DIR%\app" (
if exist "styles.css" (
if "%USE_ROBOCOPY%"=="1" (
robocopy . "%IMAGE_DIR%\app" "styles.css" /NFL /NDL /NJH /NJS >nul
) else (
copy /y "styles.css" "%IMAGE_DIR%\app\styles.css" >nul 2>&1
)
)
if exist "sounds" (
if "%USE_ROBOCOPY%"=="1" (
robocopy "sounds" "%IMAGE_DIR%\app\sounds" * /E /NFL /NDL /NJH /NJS >nul
) else (
xcopy "sounds" "%IMAGE_DIR%\app\sounds" /E /I /Y >nul 2>&1
)
)
if exist "fonts" (
if "%USE_ROBOCOPY%"=="1" (
robocopy "fonts" "%IMAGE_DIR%\app\fonts" * /E /NFL /NDL /NJH /NJS >nul
) else (
xcopy "fonts" "%IMAGE_DIR%\app\fonts" /E /I /Y >nul 2>&1
)
)
echo Also copied resources into %IMAGE_DIR%\app
)
rem Copy project-sources snapshot into image and app subfolder
echo Creating clean project-sources snapshot
rem Create a temporary snapshot folder in %TEMP% to avoid accidentally copying dist/out or other generated folders
set "SNAP=%TEMP%\fc-snapshot"
if exist "%SNAP%" rmdir /s /q "%SNAP%"
mkdir "%SNAP%"
rem Copy top-level source files and docs into snapshot
if exist "*.java" copy /y "*.java" "%SNAP%\" >nul 2>&1
if exist "*.md" copy /y "*.md" "%SNAP%\" >nul 2>&1
rem Copy src tree if present (use robocopy for reliability)
if exist "src" (
if "%USE_ROBOCOPY%"=="1" (
robocopy "src" "%SNAP%\src" * /E /NFL /NDL /NJH /NJS >nul
) else (
xcopy "src" "%SNAP%\src" /E /I /Y >nul 2>&1
)
)
rem Also include README and other helpful files
if exist "README.md" copy /y "README.md" "%SNAP%\" >nul 2>&1
rem Finally copy the snapshot into the image (and app subfolder)
if exist "%SNAP%" (
if "%USE_ROBOCOPY%"=="1" (
robocopy "%SNAP%" "%IMAGE_DIR%\project-sources" * /E /NFL /NDL /NJH /NJS >nul
) else (
xcopy "%SNAP%" "%IMAGE_DIR%\project-sources" /E /I /Y >nul 2>&1
)
echo Copied project-sources to %IMAGE_DIR%\project-sources
if exist "%IMAGE_DIR%\app" (
if "%USE_ROBOCOPY%"=="1" (
robocopy "%SNAP%" "%IMAGE_DIR%\app\project-sources" * /E /NFL /NDL /NJH /NJS >nul
) else (
xcopy "%SNAP%" "%IMAGE_DIR%\app\project-sources" /E /I /Y >nul 2>&1
)
echo Also copied project-sources into %IMAGE_DIR%\app\project-sources
)
rem Remove temporary snapshot
if exist "%SNAP%" rmdir /s /q "%SNAP%"
) else (
echo WARNING: snapshot folder not created, skipping project-sources copy
)
rem Previously the script attempted to copy project sources again from the working directory
rem which could inadvertently include the just-created image (dist) and cause recursive copies.
rem That behavior is dangerous; we intentionally avoid copying from the repository root here.
rem If additional files need to be added into '%IMAGE_DIR%\app\project-sources', create
rem a safe snapshot first (see above) or place files into 'project-sources' before packaging.
)
rem Copy JavaFX native binaries (prism_*.dll, vcruntime, etc.) into the image runtime bins
if defined JAVAFX_BIN (
if exist "%JAVAFX_BIN%" (
echo Copying JavaFX native binaries from %JAVAFX_BIN% into image runtime bins
rem Ensure runtime bin exists
if not exist "%IMAGE_DIR%\runtime\bin" mkdir "%IMAGE_DIR%\runtime\bin"
if exist "%IMAGE_DIR%\app" (
if not exist "%IMAGE_DIR%\app\runtime\bin" mkdir "%IMAGE_DIR%\app\runtime\bin"
)
rem Also ensure legacy "bin" locations exist (some jpackage layouts)
if not exist "%IMAGE_DIR%\bin" mkdir "%IMAGE_DIR%\bin"
if exist "%IMAGE_DIR%\app" (
if not exist "%IMAGE_DIR%\app\bin" mkdir "%IMAGE_DIR%\app\bin"
)
if "%USE_ROBOCOPY%"=="1" (
robocopy "%JAVAFX_BIN%" "%IMAGE_DIR%\runtime\bin" *.dll *.lib /NFL /NDL /NJH /NJS >nul
if exist "%IMAGE_DIR%\app" robocopy "%JAVAFX_BIN%" "%IMAGE_DIR%\app\runtime\bin" *.dll *.lib /NFL /NDL /NJH /NJS >nul
robocopy "%JAVAFX_BIN%" "%IMAGE_DIR%\bin" *.dll *.lib /NFL /NDL /NJH /NJS >nul
if exist "%IMAGE_DIR%\app" robocopy "%JAVAFX_BIN%" "%IMAGE_DIR%\app\bin" *.dll *.lib /NFL /NDL /NJH /NJS >nul
) else (
xcopy "%JAVAFX_BIN%\*.dll" "%IMAGE_DIR%\runtime\bin\" /Y /I >nul 2>&1
xcopy "%JAVAFX_BIN%\*.lib" "%IMAGE_DIR%\runtime\bin\" /Y /I >nul 2>&1
if exist "%IMAGE_DIR%\app" (
xcopy "%JAVAFX_BIN%\*.dll" "%IMAGE_DIR%\app\runtime\bin\" /Y /I >nul 2>&1
xcopy "%JAVAFX_BIN%\*.lib" "%IMAGE_DIR%\app\runtime\bin\" /Y /I >nul 2>&1
)
xcopy "%JAVAFX_BIN%\*.dll" "%IMAGE_DIR%\bin\" /Y /I >nul 2>&1
xcopy "%JAVAFX_BIN%\*.lib" "%IMAGE_DIR%\bin\" /Y /I >nul 2>&1
if exist "%IMAGE_DIR%\app" (
xcopy "%JAVAFX_BIN%\*.dll" "%IMAGE_DIR%\app\bin\" /Y /I >nul 2>&1
xcopy "%JAVAFX_BIN%\*.lib" "%IMAGE_DIR%\app\bin\" /Y /I >nul 2>&1
)
)
echo JavaFX native binaries copied into image.
) else (
echo WARNING: JavaFX native folder %JAVAFX_BIN% not found; skipping native copy
)
) else (
echo WARNING: JAVAFX_BIN not defined; skipping JavaFX native copy
)
endlocal