我想运行基于 Java 11 的程序(Geoserver) 在 Windows 10 主机操作系统上的 virtualbox VM 上托管的 Ubuntu 22.04 操作系统中。
由于我之前安装了 Java 18(我是按照此过程安装的),所以我
1-按照以下步骤卸载 Java 18此程序
2-重新启动虚拟机
3-运行以下命令安装 JDK 11
sudo apt update
sudo apt install openjdk-11-jdk
4-重新启动虚拟机
但是当我尝试运行基于 Java 的程序时,出现了以下错误:
GEOSERVER DATA DIR is /usr/share/geoserver/data_dir
Error: could not find libjava.so
Error: Could not find Java SE Runtime Environment.
所以我检查了我刚刚安装的 Java 版本,然后我得到了
tommaso@tommaso-VirtualBox02:/usr/share/geoserver/bin$ javac -version
javac 11.0.17
tommaso@tommaso-VirtualBox02:/usr/share/geoserver/bin$ java -version
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu222.04, mixed mode, sharing)
所以看起来,先前的 Java 版本的卸载并不顺利,并且留下了损坏的东西,以至于之后的 Java 11 安装无法正常工作。
我该如何解决?
我会排除问题取决于所安装的程序,因为Geoserver 安装步骤不涉及运行任何依赖于 Java 版本的内容。
引发错误--的文件内容startup.sh
如下:
#!/bin/sh
set -o errexit
set -o nounset
IFS=$(printf '\n\t')
# -----------------------------------------------------------------------------
# Start Script for GEOSERVER
#
# $Id$
# -----------------------------------------------------------------------------
# Guard against misconfigured JAVA_HOME
if [ -n "${JAVA_HOME:-}" ] && [ ! -x "${JAVA_HOME}/bin/java" ]; then
echo "The JAVA_HOME environment variable is set but JAVA_HOME/bin/java"
echo "is missing or not executable:"
echo " JAVA_HOME=${JAVA_HOME}"
echo "Please either set JAVA_HOME so that the Java runtime is JAVA_HOME/bin/java"
echo "or unset JAVA_HOME to use the Java runtime on the PATH."
exit 1
fi
# Find java from JAVA_HOME or PATH
if [ -n "${JAVA_HOME:-}" ]; then
_RUNJAVA="${JAVA_HOME}/bin/java"
elif [ -n "$(command -v java)" ]; then
_RUNJAVA=java
else
echo "A Java runtime (java) was not found in JAVA_HOME/bin or on the PATH."
echo "Please either set the JAVA_HOME environment variable so that the Java runtime"
echo "is JAVA_HOME/bin/java or add the Java runtime to the PATH."
exit 1
fi
if [ -z "${GEOSERVER_HOME:-}" ]; then
#If GEOSERVER_HOME not set then guess a few locations before giving
# up and demanding user set it.
if [ -r start.jar ]; then
echo "GEOSERVER_HOME environment variable not found, using current "
echo "directory. If not set then running this script from other "
echo "directories will not work in the future."
GEOSERVER_HOME="$(pwd)"
else
if [ -r ../start.jar ]; then
echo "GEOSERVER_HOME environment variable not found, using current "
echo "location. If not set then running this script from other "
echo "directories will not work in the future."
GEOSERVER_HOME="$(pwd)/.."
fi
fi
if [ -z "${GEOSERVER_HOME:-}" ]; then
echo "The GEOSERVER_HOME environment variable is not defined"
echo "This environment variable is needed to run this program"
echo "Please set it to the directory where geoserver was installed"
exit 1
fi
export GEOSERVER_HOME
fi
if [ ! -r "${GEOSERVER_HOME}/bin/startup.sh" ]; then
echo "The GEOSERVER_HOME environment variable is not defined correctly"
echo "This environment variable is needed to run this program"
exit 1
fi
#Find the configuration directory: GEOSERVER_DATA_DIR
if [ -z "${GEOSERVER_DATA_DIR:-}" ]; then
if [ -r "${GEOSERVER_HOME}/data_dir" ]; then
export GEOSERVER_DATA_DIR="${GEOSERVER_HOME}/data_dir"
else
echo "No GEOSERVER_DATA_DIR found, using application defaults"
GEOSERVER_DATA_DIR=""
fi
fi
cd "${GEOSERVER_HOME}" || exit 1
if [ -z "${MARLIN_JAR:-}" ]; then
MARLIN_JAR=$(find "$(pwd)/webapps" -name "marlin*.jar" | head -1)
if [ "${MARLIN_JAR:-}" != "" ]; then
MARLIN_ENABLER="-Xbootclasspath/a:${MARLIN_JAR}"
RENDERER="-Dsun.java2d.renderer=org.marlin.pisces.MarlinRenderingEngine"
export MARLIN_JAR MARLIN_ENABLER RENDERER
fi
fi
echo "GEOSERVER DATA DIR is ${GEOSERVER_DATA_DIR}"
#added headless to true by default, if this messes anyone up let the list
#know and we can change it back, but it seems like it won't hurt -ch
IFS=$(printf '\n\t ')
exec "${_RUNJAVA}" ${JAVA_OPTS:--DNoJavaOpts} "${MARLIN_ENABLER:--DMarlinDisabled}" "${RENDERER:--DDefaultrenderer}" "-Djetty.base=${GEOSERVER_HOME}" "-DGEOSERVER_DATA_DIR=${GEOSERVER_DATA_DIR}" -Djava.awt.headless=true -DSTOP.PORT=8079 -DSTOP.KEY=geoserver -jar "${GEOSERVER_HOME}/start.jar"
答案1
解决了
与我的想法相反,问题在于程序(地理服务器)生成了一个配置文件(/etc/default/geoserver),其中存储了安装的 Java 版本
tommaso@tommaso-VirtualBox02:/etc/default$ cat geoserver
USER=tommaso
GEOSERVER_DATA_DIR=/usr/share/geoserver/data_dir
GEOSERVER_HOME=/usr/share/geoserver
JAVA_HOME=/usr/lib/jvm/java-18-openjdk-amd64
JAVA_OPTS="-Xms128m -Xmx512m"
由于该文件位于程序自己的文件夹之外,因此仅卸载并重新安装该程序并不能解决问题。
为了解决这个问题,我遵循此程序。