B4J Tutorial How to create a StandAlone EXE without the OpenJAVA (OpenJDK)... an update for your app..

Well "@MrKim" had a wish... and talking about this... then an idea came into my mind... not a "super-duper" but a trick...
Wish:

So I am here to share it with you guys...

How to Create StandAlone Updates that will no need to include all the OpenJava (OpenJDK) files again.

* That mean, that first you must already had a Setup (for example created at Inno) extracting, copying the openjdk at the folder you want to call it afterwards, and ofcourse your basic app !

Now the standalone update…

First, make sure you already have IExpress.exe, by searching it (c:\windows\system32)… yes this tool exist for years… and is very old ! – But.. hey do not open it yet…

Create a folder in C:\, let’s say C:\myupdateproject

Into it create a batch file let’s say… test.bat

Having this code:
B4X:
@echo off

setlocal
SET CURDIR=%CD%
rem %CD:~0,3%  --> that will get current drive, without 0,3 will get current directory... but may be you wanna have it standard at c:
IF NOT EXIST "C:\java\bin\javaw.exe" GOTO DOESNOTEXIST

set alias=Reg query "HKLM\Software\Microsoft\NET Framework Setup\NDP"
FOR /F "TOKENS=6 DELIMS=\." %%A IN ('%alias%') DO set .NetVer=%%A
REM ECHO The most current version of Net in use is %.NetVer%
IF 4 GTR %.NetVer% GOTO NETVR

echo Copy Files from temp extraction folder to specific directory
md c:\test1
copy /Y *.* c:\test1
cd c:\test1

echo Let's start our JAVA JAR app...
REM i am having my openjava in c:\java ... %CD%\ for app path.. may be need used
START C:\java\bin\javaw.exe --module-path C:\java\javafx\lib --add-modules ALL-MODULE-PATH -jar "c:\test1\app.jar"

GOTO END

:NETVR
echo .Net Framework is lower than 4
powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");[Windows.Forms.MessageBox]::show(""".Net Framework is lower than 4""", """YourAPPName""",0)>nul
REM here you can download if you want... or open url
start https://support.microsoft.com/en-us/topic/microsoft-net-framework-4-8-offline-installer-for-windows-9d23f658-3b97-68ab-d013-aa3c3e7495e0

GOTO END

:DOESNOTEXIST
echo OpenJDK not exists at folder C:\java\
powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");[Windows.Forms.MessageBox]::show("""OpenJDK not exists at folder C:\java\""", """YourAPPName""",0)>nul
REM here you can download if you want... or open url
start https://b4xfiles-4c17.kxcdn.com/jdk-11.0.1.zip


:END
endlocal


In the same folder copy your built - release jar app…

Okay now run “cmd.exe” with Admin Rights, an easy way is having it at taskbar settings (wind10) instead Powershell… so right click at Start Menu… has command line (Administrator)….

Get into C:\myupdateproject, typing cd c:\myupdateproject

And run from here IExpress.exe
(have in mind running from anywhere else will not work right)


1668773842318.png

Next.. is «Επόμενο» (in greek, sorry guys)


1668773850319.png

Select first option and Next.. «Επόμενο»




1668773858654.png

Name of package… let’s say test… and Next




1668773867899.png

Next…




1668773874869.png

Next…



1668773890990.png

1668773900570.png


Add here your batch file and app.jar… Next




1668773908708.png

At Install program “cmd /c test.bat”… next




1668773915834.png

I prefer Hidden … to not show cmd shell.. but may be need to trick form to show from b4j code… next




1668773926028.png

Next…


1668773935197.png

Here you must give the exe name you wanna create… also check Hide and Store… and Next…


1668773942191.png

I like no restart… and next…




1668773949126.png

Save it for future editing… next…




1668773966915.png

Next..


1668773976347.png

And magic… creating the exe…


1668773982610.png

Τέλος… is the END !
an exe created that including batch inside of it, jar and any other file you want...

ps: I love batch files !
 
Last edited:
Top