Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ fi

# check jdk version
JAVA_VERSION=$($JAVA -version 2>&1 | awk 'NR==1{gsub(/"/,""); print $3}' | awk -F'_' '{print $1}')
if [[ $? -ne 0 || $JAVA_VERSION < $EXPECT_JDK_VERSION ]]; then

if [[ $JAVA_VERSION == 1.* ]]; then
MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f2)
else
MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f1)
fi


if [[ $? -ne 0 || $MAJOR_VERSION -lt $EXPECT_JDK_VERSION ]]; then
echo "Please make sure that the JDK is installed and the version >= $EXPECT_JDK_VERSION" >> ${OUTPUT}
exit 1
Copy link
Member

@imbajin imbajin Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic need to refactor like

#!/bin/bash
# Expected JDK version
EXPECT_JDK_VERSION=11

# Extract and check Java version
JAVA_VERSION=$(java -version 2>&1 | head -n1 | sed -n 's/.*version "\([0-9]*\)\..*/\1/p')

if [[ "$JAVA_VERSION" != "$EXPECT_JDK_VERSION" ]]; then
    echo "Expected Java ${EXPECT_JDK_VERSION}, but found Java ${JAVA_VERSION}" >> ${OUTPUT}
fi

And test it
image

fi
Comment on lines +91 to 94
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate logic?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function abs_path() {
cd -P "$(dirname "$SOURCE")" && pwd
}

REQUIRED_JAVA_VERSION="11"
BIN=$(abs_path)
TOP="$(cd "${BIN}"/../ && pwd)"
CONF="$TOP/conf"
Expand All @@ -48,15 +49,19 @@ cd "${TOP}" || exit
DEFAULT_JAVA_OPTIONS=""
JAVA_VERSION=$($JAVA -version 2>&1 | awk 'NR==1{gsub(/"/,""); print $3}' | awk -F'_' '{print $1}')

# 提取主版本号进行数值比较
# Extract the major version number for numerical comparison
if [[ $JAVA_VERSION == 1.* ]]; then
MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f2)
else
MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f1)
fi

if [[ $? -eq 0 && $MAJOR_VERSION -ge 9 ]]; then
# Compare with the required Java version
if [[ $? -eq 0 && $MAJOR_VERSION -ge $REQUIRED_JAVA_VERSION ]]; then
DEFAULT_JAVA_OPTIONS="--add-exports=java.base/jdk.internal.reflect=ALL-UNNAMED"
else
echo "Error: This application requires Java version $REQUIRED_JAVA_VERSION or higher."
exit 1
fi

echo "Initializing HugeGraph Store..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ fi

# check jdk version
JAVA_VERSION=$($JAVA -version 2>&1 | awk 'NR==1{gsub(/"/,""); print $3}' | awk -F'_' '{print $1}')
if [[ $? -ne 0 || $JAVA_VERSION < $EXPECT_JDK_VERSION ]]; then

if [[ $JAVA_VERSION == 1.* ]]; then
MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f2)
else
MAJOR_VERSION=$(echo $JAVA_VERSION | cut -d'.' -f1)
fi

if [[ $? -ne 0 || $MAJOR_VERSION -lt $EXPECT_JDK_VERSION ]]; then
echo "Please make sure that the JDK is installed and the version >= $EXPECT_JDK_VERSION" >> ${OUTPUT}
exit 1
fi
Expand Down
Loading