/JPdfBookmarks_INSTALLER_BUILD

JPdfBookmarks build native installer

Primary LanguageRoffGNU General Public License v3.0GPL-3.0

JPdfBookmarks INSTALLER BUILD

This is an auxiliary utility script files used to help jpdfbookmarks create Native Installer (Windows .msi , Linux .rpm , Linux .deb).

The following content is translated from Chinese to English using Google Translate.

1. what this auxiliary utility script files can do

  • Generate jpdfbookmarks Native Installer (Windows .msi , Linux .rpm , Linux .deb)

  • JRE has been packaged, users do not need to install JRE.

  • Users can click on the PDF file in the GUI file manager, click the right mouse button, and the system will pop up Open With, and can use jpdfbookmarks to open the PDF.

  • Users can also execute the jpdfbookmarks_cli command in the terminal as a command.

  • Users do not need to do it manually: add the installation directory to the PATH environment variable.

  • Wrappers no longer need to pack these files in:

    • exe generated by launch4j (jpdfbookmarks.exe,jpdfbookmarks_cli.exe)

    • and jpdfbookmarks, jpdfbookmarks_cli, link_this_in_linux_path.sh, link_this_in_linux_path_cli.sh.

2. How to use and execute?

Just download this project ( github.com/life888888/JPdfBookmarks_INSTALLER_BUILD/archive/refs/heads/main.zip ), unzip the zip , and then execute the corresponding command file according to your needs, you can generate the installation file of jpdfbookmarks.

downloadZIP

3. Select the corresponding command file you need to execute according to the options

3.1. Linux - RPM

3.1.1. System requirement

  • JDK 17 (Just install it with SDKMAN)

  • RPM Development Tools must be installed (sudo yum groupinstall 'RPM Development Tools')

Execute the following commands directly:
cd JPdfBookmarks_INSTALLER_BUILD/src
./build-installer-rpm-pre-setup.sh

3.1.2. Select the version you want to encapsulate

Execute the following commands directly:
# jpdfbookmarks 2.5.2
./build-installer-rpm-2.5.2.sh

# jpdfbookmarks 2.5.4
./build-installer-rpm-2.5.4.sh

# jpdfbookmarks 3.0.2
./build-installer-rpm-3.0.2.sh

3.2. Linux - DEB

3.2.1. System requirement

  • JDK 17 (Just install it with SDKMAN)

Execute the following commands directly:
cd JPdfBookmarks_INSTALLER_BUILD/src
./build-installer-deb-pre-setup.sh

3.2.2. Select the version you want to encapsulate

Execute the following commands directly:
# jpdfbookmarks 2.5.2
./build-installer-deb-2.5.2.sh

# jpdfbookmarks 2.5.4
./build-installer-deb-2.5.4.sh

# jpdfbookmarks 3.0.2
./build-installer-deb-3.0.2.sh

3.3. Windows

3.3.1. System requirement

Install JDK 17
Important

This can support the installation of 64 bit and 32 bit JDK. Please decide which version of JDK to install according to whether the msi you want to generate supports 64 bit or 32 bit.

  • Install 64 bit JDK, packaged msi, can only be installed on Windows (64 bit)

  • Install 32 bit JDK, packaged msi, can be installed on Windows (64 bit) and Windows (32 bit)

Install the 64-bit version of the JDK, execute the following commands directly:
cd JPdfBookmarks_INSTALLER_BUILD\src
build-installer-msi-pre-setup-JDK.bat
Install the 32-bit version of the JDK, execute the following commands directly:
cd JPdfBookmarks_INSTALLER_BUILD\src
build-installer-msi-pre-setup-JDK_x86_32bit.bat
Important

If your computer, executing xxx.bat will pop up Windows Protected Your PC warning window, please click More Info

Click Run anyway to continue execution.

Using Google Search "Windows Protected Your PC", the first few came up:

  • How to Disable or Remove “Windows Protected Your PC …​(2021)

  • How to bypass 'Windows protected your PC' message in …​(2021)

  • Turn off "Windows protected your PC" (Windows SmartScreen)(2012)

So this shouldn’t be a big problem…​, probably only I don’t know it(because I use Ubuntu…​)

Install WiX Toolset 3.x
Execute the following commands directly:
cd JPdfBookmarks_INSTALLER_BUILD\src
build-installer-msi-pre-setup-WiX.bat

3.3.2. Select the version you want to encapsulate

Execute the following commands directly:
build-installer-msi-2.5.2.bat

build-installer-msi-2.5.4.bat

build-installer-msi-3.0.2.bat
Important
NOTES:

If the JDK you installed is the x86 version, the generated msi will be the x86 version.

  • The x86 version of msi, the default installation location for x64 operating systems will be C:\Program Files (x86)\jpdfbookmarks

  • The x64 version of msi, the default installation location for x64 operating systems will be C:\Program Files\jpdfbookmarks

  • The msi for x86 can be installed on Windows x64, x86 versions.

  • The msi for x64 should only be installed on the Windows x64 version.

At this point, you should be able to complete the packaging of your jpdfbookmarks native installer.

Then there are broken thoughts! If you want more technical details, read further, otherwise you can close this document now.

4. Testing report

After the installation is complete, how do I verify that it works?

Test PDF files can be downloaded from here: jpdfbookmarks-test-pdf-examples-dist-1.0.0.tar.xz

4.1. Native Inatller Check Item

  • [✓] Does the splash screen appear when jpdfbookmark is executed?

  • [✓] When jpdfbookmark_cli is executed, will a console/terminal window appear?

  • [✓] When jpdfbookmark_cli is executed, splash screen should not appear.

  • [✓] Whether jpdfbookmark or jpdfbookmark_cli can be executed in any path (whether the PATH setting is successful)

  • [✓] In the file manager, when clicking on a PDF, is it possible to use the right mouse button to display jpdfbookmark?

  • [✓] In the file manager, when you click on the PDF, can you use the right mouse button? In the Open With Application list, is there a jpdfbookmark that can be selected?

4.2. Windows

4.2.1. Test Open With

Click README-zh_TW.pdf, right-click, click Open with, you should see the jpdfbookmarks icon, and Choose another application

win open with

4.2.2. First time use, License agreement screen

For the first time use, the License agreement screen, click Agree

win license

jpdfbookmarks displays PDFs containing Chinese bookmarks normally

win test 001

Only jpdfbookmarks 2.5.4 / 3.0.2 can display bookmarks with Chinese characters normally, other versions only display Chinese, Japanese, Korean, etc. as tofu character.

4.2.3. Test console / terminal mode

Open the DOS CMD window and enter the command: jpdfbookmarks_cli -e UTF-8 -d -o INDEX.txt README-zh_CN.pdf

win test 002

Modify INDEX.txt, input command: jpdfbookmarks_cli -e UTF-8 -a INDEX.txt -o README-zh_CN_NEW.pdf README-zh_CN.pdf to generate a new PDF file with bookmarks applied.

win test 003

View bookmarks in README-zh_CN_NEW.pdf is the new setting (INDEX.txt)

win test 004

Important

When running jpdfbookmarks / jpdfbookmarks_cli on Windows, please remember to add -e UTF-8, otherwise when processing non-native languages, the output file may contain ? or garbled characters.

4.3. Linux - RPM

4.3.1. Test Open With

Click README.pdf , right-click, Open With jpdfbookmarks and Open With Other Application will appear

linux rpm open with

Click Open With Other Application, the Select Application window appears, the list below appears jpdfbookmarks, jpdfbookmarks_cli, click jpdfbookmarks

linux rpm open with 2

4.3.2. First time use, License agreement screen

For the first time use, the License agreement screen, click Agree

linux rpm license

4.3.3. jpdfbookmarks GUI

The screen that jpdfbookmarks opens README.pdf appears

linux rpm test 001

4.3.4. Test jpdfbooks_cli Console/Terminal mode

Open Terminal: right-click, select Open Terminal

linux rpm test 002

Enter the command jpdfbookmarks cli --help, if there is a message as shown in the figure, it means that the settings of the installer are normal

linux rpm test 003

Input command ‵jpdfbookmarks_cli -d -o INDEX.txt README-zh_TW.pdf‵ output INDEX.txt

linux rpm test 004

Open INDEX.txt, you can see that there are normal output bookmarks

linux rpm test 005

linux rpm test 006

linux rpm test 007

Deliberately input a non-existing pdf as a test, jpdfbookmarks_cli xxx.pdf, you can go to the HOME directory to find jpdfbookmarks.0.log Check the content of the error message

linux rpm test 008

4.4. Linux -DEB

4.4.1. Test Open With

Click README-zh_TW.pdf, click the right mouse button, there will be Open With Other Application

linux deb open with

Select the application window, click jpdfbookmarks, click Select

linux deb open with 2

4.4.2. First time use, License agreement screen

For the first time use, the License agreement screen, click Agree

linux deb license

4.4.3. Chinese Bookmarks display normal

Chinese Bookmarks display normal screen shot, only jpdfbookmarks 2.5.4, 3.0.2 can display Chinese/Japanese/Korean Bookmarks normally.

fix

If you want jpdfbookmarks to display Chinese/Japanese/Korean, please download here:

4.4.4. Check jpdfbookmarks version

Click Menu Help, click About

linux deb about 3.0.2 1

The version number appears

linux deb about 3.0.2 2

5. Platform and tools

5.1. Packaging platform and test platform

5.2. Tools

  • SDKMAN - used to install JDK (Linux)

  • OpenJDK 17 - use jpackage to package as .deb, .rpm, .msi

  • WiX Toolset v3.11.2 - to assist with packaging as .msi (Windows)

6. Technical point description

In this project, the relevant technical points that can be learned are described as follows:

6.1. JPackage

In this project, the jpackage function built into JDK is mainly used.

Restriction of jpackage: Only the corresponding native installer file can be generated on a single platform (host os).

  • In Linux (deb - Ubuntu), only .deb files can be generated, and installation files in .rpm, .msi and other formats cannot be generated.

  • In Linux (rpm - Oracle Linux, Red Hat Linux), only .rpm files can be generated, and installation files in .deb, .msi and other formats cannot be generated.

  • In Windows, only .msi or .exe files can be generated, and installation files in .deb, .rpm and other formats cannot be generated.

Therefore, if you want to generate installation files corresponding to different platforms, you must go to different platforms to generate corresponding native installers one by one.

In addition, some parameters of jpakcage correspond to specific platforms. If Linux-specific parameters are given on the windows platform, an error will occur, resulting in failure to package the native installer file.

Also like the --icon parameter, Windows only accepts .ico file format, while Linux platform only accepts .png file format.

6.2. Open With function

To let the operating system know what mime type and what program to open a certain format (.pdf or .html), we can use --file-associations jpdfbookmarks.mime.properties to specify the relevant settings in an external file , the format is as follows:

jpdfbookmarks.mime.properties
mime-type=application/pdf
extension=pdf
description=PDF

Here is just to tell the OS that our jpdfbookmarks can handle pdf.

But the linux operating system does not add jpdfbookmarks to Open With.

So we overwrite the original .desktop file. Please note the %f inside, be sure to add it. In order to allow the operating system to have Open With or Open With Other Application can appear in the system menu.

jpdfbookmarks.desktop
[Desktop Entry]
Name=jpdfbookmarks
Comment=jpdfbookmarks
Exec=/opt/jpdfbookmarks/bin/jpdfbookmarks %f
Icon=/opt/jpdfbookmarks/lib/jpdfbookmarks.png
Terminal=false
Type=Application
Categories=Office
MimeType=application/pdf

6.3. Second launcher

jpackage defaults to only have one launcher point, but JPdfBookmarks has a jpdfbookmarks_cli in addition to jpdfbookmarks, it must be terminal / console , and must be no splash splash screen.

We use --add-launcher jpdfbookmarks_cli=jpdfbookmarks_cli.linux.launcher or --add-launcher jpdfbookmarks_cli=jpdfbookmarks_cli.windows.launcher to let jpackage know to add a second set of startup programs jpdfbookmarks_cli

jpdfbookmarks_cli.windows.launcher
win-console=true
java-options="-Djava.util.logging.config.file=$APPDIR/conf/jpdfbookmarks.logging.properties" "-splash:" "-ms64m" "-mx512m"

Note that the value of win-console in windows is set to true, which is used to tell the jpdfbookmarks program to start with a console. In addition, the parameters after java-options can be placed in multiple, use " to wrap, and use ` ` (space) to separate multiple parameters.

jpdfbookmarks_cli.linux.launcher
java-options="-Djava.util.logging.config.file=$APPDIR/conf/jpdfbookmarks.logging.properties" "-splash:" "-ms64m" "-mx512m"

But like in Linux there is no one called linux console, this part actually needs to be modified through the .desktop file.

Note: the following setting Terminal=true.

jpdfbookmarks_cli.desktop
[Desktop Entry]
Name=jpdfbookmarks
Comment=jpdfbookmarks
Exec=/opt/jpdfbookmarks/bin/jpdfbookmarks
Icon=/opt/jpdfbookmarks/lib/jpdfbookmarks.png
Terminal=true
Type=Application
Categories=Office
MimeType=

6.4. Make programs automatically added to PATH (Linux)

I found

  • Linux - Deb is to be added after installation through postinst, postrm is removed after removal.

  • Linux - Rpm is added and removed through jpdfbookmarks.spec.

6.4.1. Linux - Deb

postinst
...
case "$1" in
    configure)
xdg-desktop-menu install /opt/jpdfbookmarks/lib/jpdfbookmarks-jpdfbookmarks.desktop
xdg-mime install /opt/jpdfbookmarks/lib/jpdfbookmarks-jpdfbookmarks-MimeInfo.xml
xdg-desktop-menu install /opt/jpdfbookmarks/lib/jpdfbookmarks-jpdfbookmarks_cli.desktop
        # register /usr/bin/jpdfbookmarks as a jpdfbookmarks in the alternatives system
        update-alternatives \
            --install \
                /usr/bin/jpdfbookmarks \
                jpdfbookmarks \
                /opt/jpdfbookmarks/bin/jpdfbookmarks \
                50
        # register /usr/bin/jpdfbookmarks_cli as a jpdfbookmarks_cli in the alternatives system
        update-alternatives \
            --install \
                /usr/bin/jpdfbookmarks_cli \
                jpdfbookmarks_cli \
                /opt/jpdfbookmarks/bin/jpdfbookmarks_cli \
                50
    ;;
...
postrm
...
case "$1" in
    purge|remove)
           update-alternatives --remove jpdfbookmarks /usr/bin/jpdfbookmarks || true
           update-alternatives --remove jpdfbookmarks_cli /usr/bin/jpdfbookmarks_cli || true
    ;;
...

6.4.2. Linux - Rpm

jpdfbookmarks.spec
...
%post
xdg-desktop-menu install /opt/jpdfbookmarks/lib/jpdfbookmarks-jpdfbookmarks.desktop
xdg-mime install /opt/jpdfbookmarks/lib/jpdfbookmarks-jpdfbookmarks-MimeInfo.xml
xdg-desktop-menu install /opt/jpdfbookmarks/lib/jpdfbookmarks-jpdfbookmarks_cli.desktop
        # register /usr/bin/jpdfbookmarks as a jpdfbookmarks in the alternatives system
        update-alternatives \
            --install \
                /usr/bin/jpdfbookmarks \
                jpdfbookmarks \
                /opt/jpdfbookmarks/bin/jpdfbookmarks \
                50
        # register /usr/bin/jpdfbookmarks_cli as a jpdfbookmarks in the alternatives system
        update-alternatives \
            --install \
                /usr/bin/jpdfbookmarks_cli \
                jpdfbookmarks_cli \
                /opt/jpdfbookmarks/bin/jpdfbookmarks_cli \
                50
...
xdg-desktop-menu uninstall /opt/jpdfbookmarks/lib/jpdfbookmarks-jpdfbookmarks.desktop
xdg-mime uninstall /opt/jpdfbookmarks/lib/jpdfbookmarks-jpdfbookmarks-MimeInfo.xml
uninstall_default_mime_handler jpdfbookmarks-jpdfbookmarks.desktop application/pdf
xdg-desktop-menu uninstall /opt/jpdfbookmarks/lib/jpdfbookmarks-jpdfbookmarks_cli.desktop
update-alternatives --remove jpdfbookmarks /usr/bin/jpdfbookmarks || true
update-alternatives --remove jpdfbookmarks_cli /usr/bin/jpdfbookmarks_cli || true
...

6.5. Make programs automatically added to PATH (Windows)

The key command is a paragraph:

      <Component Id="pathEnvironmentVariable" Guid="{978ea978-79e0-0126-9ed7-77885b88d225}" KeyPath="yes" Directory="TARGETDIR">
        <Environment Id="MyPathVariable" Name="Path" Value="[INSTALLDIR]" Action="set" System="no" Permanent="no" Part="last" Separator=";" />
      </Component>

To add to windowsOverride\main.wxs

windowsOverride\main.wxs
...
    <!-- Standard required root -->
    <Directory Id="TARGETDIR" Name="SourceDir"/>
    <Feature Id="DefaultFeature" Title="!(loc.MainFeatureTitle)" Level="1">
      <ComponentGroupRef Id="Shortcuts"/>
      <ComponentGroupRef Id="Files"/>
      <ComponentGroupRef Id="FileAssociations"/>
      <Component Id="pathEnvironmentVariable" Guid="{978ea978-79e0-0126-9ed7-77885b88d225}" KeyPath="yes" Directory="TARGETDIR">
        <Environment Id="MyPathVariable" Name="Path" Value="[INSTALLDIR]" Action="set" System="no" Permanent="no" Part="last" Separator=";" />
      </Component>
    </Feature>
...

It is an answer message from ksenobyte.

The steps and instructions he provided are enough for me to complete this requirement.

His answer was the most valuable answer when I was searching for JPackage Wix Toolset PATH environment variable question!!!

At present, I have only seen this description, there are references to the override of JPackage on the Windows platform.

Thank you very much for this ksenobyte answer message.

Because of this information, the packaged msi can automatically set the jpdfbookmarks installation directory to the PATH environment variable.

6.6. Let jpackage override the default with a custom file

6.6.1. Linux

We use

  • --resource-dir linuxOverride to specify where is the archive directory to overwrite!!! (REF jpdfbookmarks.linux.jpackage.settings )

  • Linux can use custom files section containing launcher.png, launcher.desktop.

    • Note: The launcher here should be replaced with app name , such as jpdfbookmarks, jpdfbookmarks_cli , so the corresponding file will be jpdfbookmarks.png, jpdfbookmarks_cli.png , jpdfbookmarks.desktop, jpdfbookmarks_cli.desktop.

  • Linux DEBs can use custom file sections containing control, preinst, prerm, postinst, postrm, copyright.

  • Linux RPMs can use the custom file section to include package-name.spec, where the package-name is the same as the app name, so it will be jpdfbookmarks.spec.

6.6.2. Windows:

  • --resource-dir windowsOverride specify resource directory to provide custom files!!! (REF jpdfbookmarks.windows.jpackage.settings )

6.7. How do I know which files to overwrite?

When executing jpackage, just add --temp xxxx, you can find the file that jpackage needs to package according to your parameters in the xxxx directory, we can copy the part that needs to be modified, and then modify it.

I copied the modified part to the linux Override directory.

The aforementioned jpdfbookmarks.desktop, jpdfbookmarks_cli.desktop and postinst, postrm, jpdfbookmarks.spec are copied from jpackage plus --temp xxxx output xxxx subdirectory, be modified.

Important
LIMIT
  • If we change the app name and launcher name, the files in the corresponding build image will also be changed. Please remember to redo --temp xxxx , copy the related files such as xxxxx.desktop, yyyyy_cli.desktop and postinst, postrm , xxxxx.spec and other files to modify.

  • In addition, it is recommended to use lowercase for the name.

6.8. Restrictions - jpdfbookmarks.spec

Version: 3.0.2 is written in jpdfbookmarks.spec, I have to copy multiple files with the same content, and then modify Version: xxx, so I have jpdfbookmarks.spec.2.5.2, jpdfbookmarks .spec.2.5.4, jpdfbookmarks.spec.3.0.2 Before executing, copy jpdfbookmarks.spec.2.5.2 to jpdfbookmarks.spec

6.9. Refinement of JRE Runtime image

If no additional parameters are set, jpackage will automatically package jre for you.

But jpackage can decide which modules to package according to the given module in ‵--add-modules‵.

The msi/deb/rpm of jpdfbookmarks with the ‵--add-modules‵ parameter can be changed from 58 MB to 34 MB.

6.9.1. How to know which modules to add to add-modules?

Find out which modules are required by jpdfbookmarks.jar
jdeps -cp "lib/*" \
    --module-path "lib/*" \
    --multi-release 9 \
    --print-module-deps \
    --ignore-missing-deps \
    jpdfbookmarks.jar

Then go to the lib directory and use the jars in it to find the corresponding module with instructions similar to the above.

Finally, sort them out, and then use , to separate them.

Adding the parameter ‵--add-modules‵ directly to jpackage will allow the simplified jre image to be applied.

6.10. Unrestricted Java applications compiled and packaged with JDK 9 or later can be used

In this project, we directly download jpdfbookmarks 2.5.2 (compiled and packaged with Java 6), unpack it, and then use the jpackage command to repackage it.

So regardless of whether your program is compiled and packaged with JDK 9+, you can use jpackage to repackage the native installer.

But the packaged JDK version must be at least 14+, because JDK 14+ only has the jpackage command to use.

6.11. Java Options And Splash Screen

You can use java-options to specify parameters that would otherwise be given by external parameters, such as -DXXXXX , -mxXXXm, -msXXXm.

--java-options "-Djava.util.logging.config.file=$APPDIR/conf/jpdfbookmarks.logging.properties"
--java-options "-splash:$APPDIR/splash.png"
--java-options "-ms64m"
--java-options "-mx512m"

In addition, it should be noted that the Splash screen, if it was originally set in the main jar, will not take effect here, and must be given through the java-options parameter.

Alternatively, you can use the $APPDIR proxy to wrap the installation directory.

--java-options "-splash:$APPDIR/splash.png"

6.12. Command set PATH environment variable

A few highlights:

  • How to call PowerShell from BAT file

setupPATH.bat
PowerShell.exe -command ".\addPATH.ps1"
  • Power Shell, finds the current directory location, and adds it to the user’s PATH environment variable. (If it is an environment variable to be added to the system level, the following User should be changed to Machine.

addPATH.ps1
$dir = Get-Location

$path = [Environment]::GetEnvironmentVariable('PATH', 'User') -split ';' |
        Where-Object { $_ -ne $dir }
$path += $dir
[Environment]::SetEnvironmentVariable('PATH', ($path -join ';'), 'User')
  • deprecated - Powser Shell, if you want to find the previous directory of the current directory location (‵$dir = Split-Path -Path $dir -Parent‵), and add it to the user’s PATH environment variable. (If it is an environment variable to be added to the system level, the following User should be changed to Machine.

add-jpdfbookmarks-PATH.ps1
$dir = Get-Location

$dir = Split-Path -Path $dir -Parent

$path = [Environment]::GetEnvironmentVariable('PATH', 'User') -split ';' |
        Where-Object { $_ -ne $dir }
$path += $dir
[Environment]::SetEnvironmentVariable('PATH', ($path -join ';'), 'User')

6.13. Windows Fool Check

6.13.1. Check if a command exists

Use WHERE xxx, to confirm whether the xxx command exists? If the xxx command does not exist, ‵%ERRORLEVEL%‵ is not equal to ‵0`.

This can be used to check whether WiX has been successfully configured and whether jpackage can be found (JDK 11 does not have jpackage, so it will not fail when the jpackage command is executed later)

WHERE light
IF %ERRORLEVEL% NEQ 0 (
    ECHO light command wasn't found, please check WiX Toolset Install is finish?
	goto WiX_NOT_READY
) ELSE (
    REM ECHO light command is ready. Process next step...
	goto WiX_READY
)

6.13.2. Check if decompression failed

Sometimes, due to download problems, the downloaded zip file is incomplete, and subsequent decompression will fail, so we need to use %ERRORLEVEL% to check whether the decompression fails after decompression.

jar -xvf  jpdfbookmarks-2.5.2.zip

REM CHECK UNZIP IS OK ?
IF %ERRORLEVEL% NEQ 0 (
    ECHO UNZIP  jpdfbookmarks-2.5.2.zip IS FAIL !
	goto JPDFBOOKMARKS_FILE_NOT_READY
) ELSE (
    REM ECHO jar command is ready. Process next step...
	goto JPDFBOOKMARKS_FILE_UNZIP_READY
)

6.14. Use system build-in commands or trusted third-party tool commands as much as possible on Windows

  • Downloading Archives - Using Windows 10’s built-in curl command

  • Unzip Archive - Unzip using the JDK built-in jar command

6.15. Command to install msi file on Windows and give parameters

  • Originally, we need to specifically declare that two options need to be checked when installing JDK manually. Now we can directly specify parameters through msiexec command (FeatureJavaHome, FeatureOracleJavaSoft is to let the installer set the environment variable JAVA_HOME and the Windows code of Oracle Java Soft.

msiexec /i OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.msi ADDLOCAL=FeatureEnvironment,FeatureJarFileRunWith,FeatureJavaHome,FeatureOracleJavaSoft /qb
  • If needed, we can add INSTALLDIR="C:\TOOLS\jpdfbookmarks" to directly give the installation directory of jpdfbookmarks.

msiexec /i jpdfbookmarks-3.0.2_x64.msi INSTALLDIR="C:\TOOLS\jpdfbookmarks" /qb
  • The parameter /qb only displays the most basic GUI, omits other processes, and executes the installation directly.

6.16. Strange trap error during testing

6.16.1. jpackage always reports an error: Error: Invalid or unsupported type: [null] or Error: Invalid or unsupported type: [rpm]

Out-of-the-box vagrant box settings to use when testing jpackage with Oracle Linux (RPM):

$ mkdir VM_oraclelinux_8-btrfs
$ cd VM_oraclelinux_8-btrfs
$ vagrant init oraclelinux/8-btrfs https://oracle.github.io/vagrant-projects/boxes/oraclelinux/8-btrfs.json
$ vagrant up
$ vagrant ssh
...

Using jpackage always reports an error: Error: Invalid or unsupported type: [null] or Error: Invalid or unsupported type: [rpm]

This error, originally thought to be related to using SDKMAN to install jdk, and later using yum install java-17* is no solution!!!

The final solution is: To install 'RPM Development Tools'.

The command is sudo yum groupinstall 'RPM Development Tools'

Here it is organized in build-installer-rpm-pre-setup.sh.

6.16.2. Windows curl fails to automatically download JDK in bat file

In Windows, use curl to automatically download JDK, manually paste the download URL in CMD.exe, and the download can be successful, but after pasting it into the bat file, the execution of the bat file will always fail.

Check the JDK download URL (github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.2%2B8/OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.msi) contains a special character ‵%‵, which causes bat to fail.

The solution is to use %% to avoid errors.

use %% to avoid errors.
curl -L -o OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.msi "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.2%%2B8/OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.msi"

So now this version of the bat file can be done so that the JDK can be downloaded automatically.

6.16.3. Setting environment variables using the setx command will result in multiple duplicate settings

The original instruction used setx to set environment variables, but it was flawed and caused multiple duplicate settings.

So now abandon the use of setx, and use the powershell method to set (REF addPATH.ps1).

The conclusion is don’t use setx.

6.16.4. The msi file downloaded from Github cannot be directly clicked to install

The msi file downloaded from Github, when you click to install directly, Windows will pop up Windows protected your PC, and then won’t let you install!!!

  • Solution 1: In fact, it can still be installed, just click More info in the prompt window, and then click Run anyway to force the installation.

  • Solution 2: Use the command line to install instead, use the command to install msiexec -i jpdfbookmarks-3.0.2_x64.msi /qb , you can install it directly without popping out the warning window.

6.16.5. After Linux finishes installing SDKMAN and installing JDK through SDKMAN, the subsequent shell script cannot find command jpackage

Because after installing SDKMAN in Linux, the environment variables will be set, but the environment variables will not take effect until a new Terminal is opened. JDK, but the subsequent shell script in the current terminal will not find the jpackage command.

The solution is to prompt the user to close the current Terminal after installing SDKMAN and JDK, and let the user close the current Terminal and then reopen the new Terminal.

6.17. Command simplification

  • Extract the platform-related parameters to an external file, use @XXXX ,

  • Make the command body almost similar, separate the platform-specific or format-related ones in external files,

  • In addition, the command body extracted from the version-specific part:

deb build
jpackage @jpdfbookmarks.app.jpackage.settings \
 @jpdfbookmarks.linux.jpackage.settings  \
 --add-launcher jpdfbookmarks_cli=jpdfbookmarks_cli.linux.launcher  \
 --linux-app-release snapshot-1 \
 --linux-deb-maintainer "Flaviano Petrocchi<flavianopetrocchi@gmail.com>" \
 --app-version 3.0.2 \
 --add-modules  java.base,java.datatransfer,java.desktop,java.logging,java.management,java.naming,java.prefs,java.sql,java.xml
rpm build
jpackage @jpdfbookmarks.app.jpackage.settings \
 @jpdfbookmarks.linux.jpackage.settings  \
 --add-launcher jpdfbookmarks_cli=jpdfbookmarks_cli.linux.launcher  \
 --linux-app-release snapshot-1 \
 --app-version 3.0.2 \
 --add-modules  java.base,java.datatransfer,java.desktop,java.logging,java.management,java.naming,java.prefs,java.sql,java.xml
msi build
jpackage @jpdfbookmarks.app.jpackage.settings ^
 @jpdfbookmarks.windows.jpackage.settings ^
 --add-launcher jpdfbookmarks_cli=jpdfbookmarks_cli.windows.launcher  ^
 --app-version 3.0.2 ^
 --add-modules   java.base,java.datatransfer,java.desktop,java.logging,java.management,java.naming,java.prefs,java.sql,java.xml

7. TODO

  • [✓] msi for Windows: Modify the settings in WiX so that the msi installation file can automatically add the installation directory of jpdfbookmarks to the PATH environment variable after the installation is complete. I have not found out how to complete this part. (Done.)

  • ❏ MacOS packaging: I will talk about it later if I have a MacOS environment!!!

8. Limit

No wrapper directive for MacOS?

Yes, no! Because I don’t have a MacOS environment to test!!!

9. Reference

10. Package output of this auxiliary tool

The following outputs are produced through this tool command:

11. Summary

  • In this project, you can use this project to help you repackage jpdfbookmarks' native installer on your machine.

  • The new Native Installer allows you to use Open With after installation, use the file manager, and click on the PDF.

  • The new Native Installer allows you to install without having to set PATH or to link to /usr/bin (Linux).

  • The new Native Installer allows you to install without having to set PATH (Windows - WiX Toolset).

  • There are also the pit encountered in the execution of jpackage in Linux - RPM and the solution I found by myself.

  • How to use jpackage’s override.

  • How to use jpackage’s @ files.

  • In this project, the different aspects of parameter usage of multiple jpackages are shown, so that you can better understand the meaning of the parameters in the file!!!

  • In the same way, you can repackage your own or someone else’s executable jar into a native installer (msi, deb, rpm).