Jenkins在jdk17的Tomcat上运行报错
Jenkins在jdk17的Tomcat上运行报错
一、环境
宝塔:tomcat8.0
jdk:jdk17
二、保存项目时报错
Unable to make field protected transient int java.util.AbstractList.modCount accessible: module java.base does not "opens java.util" to unnamed module @6d15ca84
查看 localhost 日志如下
07-Feb-2024 14:10:42.445 严重 [Handling POST /jenkins/job/Contract-Management-System/configSubmit from 127.0.0.1 : http-nio-8080-exec-9] org.apache.catalina.core.ApplicationContext.log Error while serving http://jenkins.anhaoyang.com/jenkins/job/Contract-Management-System/configSubmit
java.lang.reflect.InvocationTargetException
...
at java.base/java.lang.Thread.run(Thread.java:842)
Caused by: java.io.IOException: java.lang.RuntimeException: Failed to serialize hudson.model.AbstractProject#scm for class hudson.model.FreeStyleProject
... 89 more
Caused by: java.lang.RuntimeException: Failed to serialize hudson.model.AbstractProject#scm for class hudson.model.FreeStyleProject
...
at com.thoughtworks.xstream.XStream.toXML(XStream.java:1265)
at hudson.XmlFile.write(XmlFile.java:216)
... 97 more
Caused by: java.lang.RuntimeException: Failed to serialize hudson.plugins.git.GitSCM#submoduleCfg for class hudson.plugins.git.GitSCM
...
at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:270)
... 110 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field protected transient int java.util.AbstractList.modCount accessible: module java.base does not "opens java.util" to unnamed module @6d15ca84
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
at com.thoughtworks.xstream.converters.reflection.FieldDictionary.buildDictionaryEntryForClass(FieldDictionary.java:176)
at com.thoughtworks.xstream.converters.reflection.FieldDictionary.buildMap(FieldDictionary.java:142)
at com.thoughtworks.xstream.converters.reflection.FieldDictionary.fieldsFor(FieldDictionary.java:80)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:167)
at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:206)
at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:163)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:50)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:283)
at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:270)
... 119 more
三、根本原因
从jdk9开始,新增了模块特性,模块中的类要使得能访问需要open出来
因此,要强行可用,需增加jvm参数
方法一:在setenv.sh
文件中设置
# Tomcat的JVM参数设置
export JAVA_OPTS="--add-opens=java.base/jdk.interna=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED $JAVA_OPTS"
方法二:在daemon.sh
文件中设置 JAVA_OPTS 参数,修改后如下
宝塔中只使用
daemon.sh
这个文件,可以在里面设置JAVA_HOME或其他变量,修改后会同步到面板中
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -----------------------------------------------------------------------------
# Commons Daemon wrapper script.
# -----------------------------------------------------------------------------
# resolve links - $0 may be a softlink
PRG="$0"
while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
DIRNAME="`dirname "$PRG"`"
PROGRAM="`basename "$PRG"`"
while [ ".$1" != . ]
do
case "$1" in
--java-home )
JAVA_HOME="$2"
shift; shift;
continue
;;
--catalina-home )
CATALINA_HOME="$2"
shift; shift;
continue
;;
--catalina-base )
CATALINA_BASE="$2"
shift; shift;
continue
;;
--catalina-pid )
CATALINA_PID="$2"
shift; shift;
continue
;;
--tomcat-user )
TOMCAT_USER="$2"
shift; shift;
continue
;;
--service-start-wait-time )
SERVICE_START_WAIT_TIME="$2"
shift; shift;
continue
;;
* )
break
;;
esac
done
# OS specific support (must be 'true' or 'false').
cygwin=false;
darwin=false;
case "`uname`" in
CYGWIN*)
cygwin=true
;;
Darwin*)
darwin=true
;;
esac
# Use the maximum available, or set MAX_FD != -1 to use that
test ".$MAX_FD" = . && MAX_FD="maximum"
# Setup parameters for running the jsvc
#
test ".$TOMCAT_USER" = . && TOMCAT_USER=www
# Set JAVA_HOME to working JDK or JRE
#JAVA_HOME=/usr/local/btjdk/jdk8
JAVA_HOME=/usr/local/java/jdk-17.0.10
# If not set we'll try to guess the JAVA_HOME
# from java binary if on the PATH
#
if [ -z "$JAVA_HOME" ]; then
JAVA_BIN="`which java 2>/dev/null || type java 2>&1`"
while [ -h "$JAVA_BIN" ]; do
ls=`ls -ld "$JAVA_BIN"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
JAVA_BIN="$link"
else
JAVA_BIN="`dirname "$JAVA_BIN"`/$link"
fi
done
test -x "$JAVA_BIN" && JAVA_HOME="`dirname "$JAVA_BIN"`"
test ".$JAVA_HOME" != . && JAVA_HOME=`cd "$JAVA_HOME/.." >/dev/null; pwd`
else
JAVA_BIN="$JAVA_HOME/bin/java"
fi
# Only set CATALINA_HOME if not already set
test ".$CATALINA_HOME" = . && CATALINA_HOME=`cd "$DIRNAME/.." >/dev/null; pwd`
test ".$CATALINA_BASE" = . && CATALINA_BASE="$CATALINA_HOME"
test ".$CATALINA_MAIN" = . && CATALINA_MAIN=org.apache.catalina.startup.Bootstrap
# If not explicitly set, look for jsvc in CATALINA_BASE first then CATALINA_HOME
if [ -z "$JSVC" ]; then
JSVC="$CATALINA_BASE/bin/jsvc"
if [ ! -x "$JSVC" ]; then
JSVC="$CATALINA_HOME/bin/jsvc"
fi
fi
# Set the default service-start wait time if necessary
test ".$SERVICE_START_WAIT_TIME" = . && SERVICE_START_WAIT_TIME=10
# Ensure that any user defined CLASSPATH variables are not used on startup,
# but allow them to be specified in setenv.sh, in rare case when it is needed.
CLASSPATH=
JAVA_OPTS="--add-opens=java.base/java.util=ALL-UNNAMED"
if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
. "$CATALINA_BASE/bin/setenv.sh"
elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
. "$CATALINA_HOME/bin/setenv.sh"
fi
# Add on extra jar files to CLASSPATH
test ".$CLASSPATH" != . && CLASSPATH="$CLASSPATH:"
CLASSPATH="$CLASSPATH$CATALINA_HOME/bin/bootstrap.jar:$CATALINA_HOME/bin/commons-daemon.jar"
test ".$CATALINA_OUT" = . && CATALINA_OUT="$CATALINA_BASE/logs/catalina-daemon.out"
test ".$CATALINA_TMP" = . && CATALINA_TMP="$CATALINA_BASE/temp"
# Add tomcat-juli.jar to classpath
# tomcat-juli.jar can be over-ridden per instance
if [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; then
CLASSPATH="$CLASSPATH:$CATALINA_BASE/bin/tomcat-juli.jar"
else
CLASSPATH="$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jar"
fi
# Check for the deprecated LOGGING_CONFIG
# Only use it if CATALINA_LOGGING_CONFIG is not set and LOGGING_CONFIG starts with "-D..."
if [ -z "$CATALINA_LOGGING_CONFIG" ]; then
case $LOGGING_CONFIG in
-D*) CATALINA_LOGGING_CONFIG="$LOGGING_CONFIG"
esac
fi
# Set juli LogManager config file if it is present and an override has not been issued
if [ -z "$CATALINA_LOGGING_CONFIG" ]; then
if [ -r "$CATALINA_BASE/conf/logging.properties" ]; then
CATALINA_LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
else
# Bugzilla 45585
CATALINA_LOGGING_CONFIG="-Dnop"
fi
fi
test ".$LOGGING_MANAGER" = . && LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
# Set -pidfile
test ".$CATALINA_PID" = . && CATALINA_PID="$CATALINA_BASE/logs/catalina-daemon.pid"
# Increase the maximum file descriptors if we can
if [ "$cygwin" = "false" ]; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ "$?" -eq 0 ]; then
# Darwin does not allow RLIMIT_INFINITY on file soft limit
if [ "$darwin" = "true" ] && [ "$MAX_FD_LIMIT" = "unlimited" ]; then
MAX_FD_LIMIT=`/usr/sbin/sysctl -n kern.maxfilesperproc`
fi
test ".$MAX_FD" = ".maximum" && MAX_FD="$MAX_FD_LIMIT"
ulimit -n $MAX_FD
if [ "$?" -ne 0 ]; then
echo "$PROGRAM: Could not set maximum file descriptor limit: $MAX_FD"
fi
else
echo "$PROGRAM: Could not query system maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# Set UMASK unless it has been overridden
if [ -z "$UMASK" ]; then
UMASK="0027"
fi
umask $UMASK
# Java 9 no longer supports the java.endorsed.dirs
# system property. Only try to use it if
# JAVA_ENDORSED_DIRS was explicitly set
# or CATALINA_HOME/endorsed exists.
ENDORSED_PROP=ignore.endorsed.dirs
if [ -n "$JAVA_ENDORSED_DIRS" ]; then
ENDORSED_PROP=java.endorsed.dirs
fi
if [ -d "$CATALINA_HOME/endorsed" ]; then
ENDORSED_PROP=java.endorsed.dirs
fi
# ----- Execute The Requested Command -----------------------------------------
case "$1" in
run )
shift
eval exec "\"$JSVC\"" $* \
"$JSVC_OPTS" \
-java-home "\"$JAVA_HOME\"" \
-pidfile "\"$CATALINA_PID\"" \
-wait $SERVICE_START_WAIT_TIME \
-umask $UMASK \
-nodetach \
-outfile "\"&1\"" \
-errfile "\"&2\"" \
-classpath "\"$CLASSPATH\"" \
"\"$CATALINA_LOGGING_CONFIG\"" "$JAVA_OPTS" "$CATALINA_OPTS" \
-D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMP\"" \
$CATALINA_MAIN
exit $?
;;
start )
eval "\"$JSVC\"" \
"$JSVC_OPTS" \
-java-home "\"$JAVA_HOME\"" \
-user $TOMCAT_USER \
-pidfile "\"$CATALINA_PID\"" \
-wait $SERVICE_START_WAIT_TIME \
-umask $UMASK \
-outfile "\"$CATALINA_OUT\"" \
-errfile "\"&1\"" \
-classpath "\"$CLASSPATH\"" \
"\"$CATALINA_LOGGING_CONFIG\"" "$JAVA_OPTS" "$CATALINA_OPTS" \
-D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMP\"" \
$CATALINA_MAIN
exit $?
;;
stop )
eval "\"$JSVC\"" \
"$JSVC_OPTS" \
-stop \
-pidfile "\"$CATALINA_PID\"" \
-classpath "\"$CLASSPATH\"" \
-D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMP\"" \
$CATALINA_MAIN
exit $?
;;
version )
"$JSVC" \
-java-home "$JAVA_HOME" \
-pidfile "$CATALINA_PID" \
-classpath "$CLASSPATH" \
-errfile "&2" \
-version \
-check \
$CATALINA_MAIN
if [ "$?" = 0 ]; then
"$JAVA_BIN" \
-classpath "$CATALINA_HOME/lib/catalina.jar" \
org.apache.catalina.util.ServerInfo
fi
exit $?
;;
* )
echo "Unknown command: '$1'"
echo "Usage: $PROGRAM ( commands ... )"
echo "commands:"
echo " run Start Tomcat without detaching from console"
echo " start Start Tomcat"
echo " stop Stop Tomcat"
echo " version What version of commons daemon and Tomcat"
echo " are you running?"
exit 1
;;
esac