Gradle 7.3
Java 1.8
Here my build.gradle:
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
// Build uber-jar
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
// https://github.com/NocWriter/runsql-gradle-plugin
id "com.nocwriter.runsql" version "1.0.3"
}
apply plugin: "com.github.johnrengelman.shadow"
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
}
application {
applicationName = "${projectShortName}" // /bin/m2cm.bat
mainClass = javaMainClass
applicationDefaultJvmArgs = ["-splash:${buildDir}/resources/main/images/splash.png"]
}
dependencies {
implementation 'log4j:log4j:1.2.17'
implementation 'org.xerial:sqlite-jdbc:3.36.0.3'
implementation 'com.toedter:jcalendar:1.4'
dependencies { implementation name: 'ssp-0.5.6' }
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
}
jar {
exclude("db")
archiveFileName = "${projectShortName}.jar"
manifest {
attributes(
"Main-Class": "$javaMainClass",
"SplashScreen-Image": "images/splash.png")
}
}
I run myProject like this:
./gradle run
As result success show splash screen. Because has this settings:
applicationDefaultJvmArgs = ["-splash:${buildDir}/resources/main/images/splash.png"]
Nice.
Now I create distributive like this:
gradle distZip
As result create zip with myProject.jar in lib folder.
OK. The splash screen (splash.png) is in jar file: /lib/myProject.jar
The distZip also generate bin/myProj.bat with the next content:
@if "%DEBUG%" == "" @echo off
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%..
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and M2CM_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-splash:C:\dev\temp\m2cm\app\build/resources/main/images/splash.png"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\lib\m2cm.jar;%APP_HOME%\lib\log4j-1.2.17.jar;%APP_HOME%\lib\sqlite-jdbc-3.36.0.3.jar;%APP_HOME%\lib\jcalendar-1.4.jar;%APP_HOME%\lib\ssp-0.5.6.jar
@rem Execute m2cm
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %M2CM_OPTS% -classpath "%CLASSPATH%" com.mycompany.myproject.Main %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable M2CM_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%M2CM_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
And when client run my app by myProj.bat the splash screen is NOT show. This is because in client no this path:
C:\dev\temp\m2cm\app\build/resources/main/images/splash.png"
Is it possible to create distributive by Gradle to show splash screen on client (production)?
This also NOT help
manifest {
attributes(
"Main-Class": "$javaMainClass",
"SplashScreen-Image": "images/splash.png")
}