Skip to content

Commit 1aef6be

Browse files
committed
feat(packaging): add Windows EXE jpackage script, Launch4j wrapper script, and Gradle packaging tasks (EXE/MSI/DMG/DEB); update README with one-command usage and size notes
1 parent 9732f7d commit 1aef6be

File tree

4 files changed

+116
-2
lines changed

4 files changed

+116
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,15 @@ Notas importantes:
187187
- Compilar: `gradle clean build`
188188
- Executar: `gradle run` ou `java -jar build\libs\BiByte-<versao>.jar`
189189
- Empacotar (opcional):
190-
- `jpackage --type msi --name BiByte --app-version <versao> --input build\libs --main-jar BiByte-<versao>.jar --main-class bitbyte.MyJFrame --dest out\win --icon process-icon1.ico`
191-
- Alternativa (legado): Launch4j com `bitbyte_Launch4j.xml` (hoje preferimos `jpackage`).
190+
- Gradle (um comando):
191+
- `gradle packageWinExe` (gera EXE auto-contido em `out\win`) — maior (inclui runtime)
192+
- `gradle packageWinMsi` (gera MSI auto-contido em `out\win`) — maior (inclui runtime)
193+
- Scripts (PowerShell):
194+
- EXE: `$env:VERSION="<versao>"; ./scripts/jpackage-win-exe.ps1`
195+
- MSI: `$env:VERSION="<versao>"; ./scripts/jpackage-win.ps1`
196+
- Alternativa enxuta (depende de Java instalado):
197+
- Launch4j: `./scripts/launch4j-win.ps1` (gera .exe pequeno; requer JRE instalado no sistema ou apontar JRE embarcado no XML)
198+
- Observação: jpackage cria instaladores auto-contidos (sem depender de Java instalado), porém com tamanho maior.
192199

193200
### Observações sobre Arquitetura (arm64 vs amd64)
194201
- O JAR (bytecode Java) é multiplataforma. O mesmo artefato roda em qualquer SO/arquitetura com JVM compatível.

build.gradle

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,63 @@ jar {
4444
}
4545
}
4646

47+
// Packaging helpers using jpackage (requires JDK with jpackage on PATH)
48+
def appName = 'BiByte'
49+
def mainClassFqn = 'bitbyte.MyJFrame'
50+
def jarFile = { "${appName}-${project.version}.jar" }
51+
52+
tasks.register('packageWinExe', Exec) {
53+
dependsOn(tasks.named('build'))
54+
commandLine 'jpackage',
55+
'--type', 'exe',
56+
'--name', appName,
57+
'--app-version', project.version,
58+
'--input', 'build/libs',
59+
'--main-jar', jarFile(),
60+
'--main-class', mainClassFqn,
61+
'--dest', 'out/win',
62+
'--icon', 'process-icon1.ico'
63+
}
64+
65+
tasks.register('packageWinMsi', Exec) {
66+
dependsOn(tasks.named('build'))
67+
commandLine 'jpackage',
68+
'--type', 'msi',
69+
'--name', appName,
70+
'--app-version', project.version,
71+
'--input', 'build/libs',
72+
'--main-jar', jarFile(),
73+
'--main-class', mainClassFqn,
74+
'--dest', 'out/win',
75+
'--icon', 'process-icon1.ico'
76+
}
77+
78+
tasks.register('packageMacDmg', Exec) {
79+
dependsOn(tasks.named('build'))
80+
commandLine 'jpackage',
81+
'--type', 'dmg',
82+
'--name', appName,
83+
'--app-version', project.version,
84+
'--input', 'build/libs',
85+
'--main-jar', jarFile(),
86+
'--main-class', mainClassFqn,
87+
'--dest', 'out/mac',
88+
'--icon', 'process-icon1.ico'
89+
}
90+
91+
tasks.register('packageDeb', Exec) {
92+
dependsOn(tasks.named('build'))
93+
commandLine 'jpackage',
94+
'--type', 'deb',
95+
'--name', appName,
96+
'--app-version', project.version,
97+
'--input', 'build/libs',
98+
'--main-jar', jarFile(),
99+
'--main-class', mainClassFqn,
100+
'--dest', 'out/deb',
101+
'--icon', 'process-icon1.ico'
102+
}
103+
47104
sourceSets {
48105
main {
49106
java {

scripts/jpackage-win-exe.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Windows EXE packaging using jpackage.
2+
# Usage (PowerShell): $env:VERSION="2.0.2"; ./scripts/jpackage-win-exe.ps1
3+
4+
$ErrorActionPreference = 'Stop'
5+
6+
$VERSION = if ($env:VERSION) { $env:VERSION } else { 'dev' }
7+
$APP_NAME = 'BiByte'
8+
$MAIN_CLASS = 'bitbyte.MyJFrame'
9+
$JAR_DIR = 'build\libs'
10+
$ICON = 'process-icon1.ico'
11+
$DEST = 'out\win'
12+
13+
New-Item -ItemType Directory -Force -Path $DEST | Out-Null
14+
15+
& jpackage `
16+
--type exe `
17+
--name $APP_NAME `
18+
--app-version $VERSION `
19+
--input $JAR_DIR `
20+
--main-jar "$APP_NAME-$VERSION.jar" `
21+
--main-class $MAIN_CLASS `
22+
--dest $DEST `
23+
--icon $ICON
24+
25+
Write-Host "EXE created in $DEST"
26+

scripts/launch4j-win.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Build a small Windows .exe wrapper using Launch4j.
2+
# Requires Launch4j installed (e.g., `choco install launch4j`) and bitbyte_Launch4j.xml in repo root.
3+
4+
$ErrorActionPreference = 'Stop'
5+
6+
$LAUNCH4J = ${env:LAUNCH4J_EXE}
7+
if (-not $LAUNCH4J) {
8+
# Common default install path
9+
$LAUNCH4J = "C:\Program Files (x86)\Launch4j\launch4jc.exe"
10+
}
11+
12+
if (-not (Test-Path $LAUNCH4J)) {
13+
Write-Error "Launch4j not found. Set LAUNCH4J_EXE env var or install via Chocolatey."
14+
}
15+
16+
$CONFIG = "bitbyte_Launch4j.xml"
17+
if (-not (Test-Path $CONFIG)) {
18+
Write-Error "Missing $CONFIG in repo root."
19+
}
20+
21+
& "$LAUNCH4J" "$CONFIG"
22+
23+
Write-Host "Launch4j .exe generated per $CONFIG"
24+

0 commit comments

Comments
 (0)