Running H2 Database as a User Binary

18 views
Skip to first unread message

TINSAE TADESSE GUTEMA

unread,
Sep 20, 2025, 3:41:26 PM (3 days ago) Sep 20
to H2 Database

The steps below provide a solution for running the H2 Database console from a ZIP installation while ensuring it operates correctly as a user binary.

1. Install H2 Database

Ensure you have extracted the H2 Database ZIP file to your desired location, e.g., /opt/h2/.

2. Create a Soft Link

Create a soft link to the H2 script for easy access:
$ ln -s /opt/h2/bin/h2.sh /usr/local/bin/h2

3. Modify the h2.sh Script

Edit the h2.sh script to ensure the correct directory is used regardless of how it's executed. Replace the content with the following:
#!/bin/sh
dir=$(dirname "$(readlink -f "$0")")  # Changed from the original line
java -cp "$dir/h2-2.3.232.jar:$H2DRIVERS:$CLASSPATH" org.h2.tools.Console "$@"

4. Test the Setup

You can now run the H2 Database console from anywhere in the terminal by simply typing:
$ h2

Explanation

The line dir=$(dirname "$(readlink -f "$0")") is added to resolve the absolute path of the script. This ensures that the script can locate the h2-2.3.232.jar file correctly, regardless of the current working directory or how the script is executed (e.g., via the soft link). Without this change to the line, the following error would be displayed when you run h2 after creating the symbolic link:

Error: Could not find or load main class org.h2.tools.Console
Caused by: java.lang.ClassNotFoundException: org.h2.tools.Console

Reply all
Reply to author
Forward
0 new messages