I want to run tomcat with a javaagent.
setenv.sh:
export JAVA_HOME=/home/ggfan/1-install/java/jdk1.8.0_271
export CATALINA_OPTS="${CATALINA_OPTS} -javaagent:/home/ggfan/2-work/centuari-space/jdbc-leak-detector/target/jdbcld.jar=/home/ggfan/3-tmp/logs/jdbcld,INFO,org.apache.commons.dbcp.PoolingDataSource\$PoolGuardConnectionWrapper"
call startup.sh, seems tomcat picked it correctly:
[ggfan@localhost bin]$ ./startup.sh
Using CATALINA_BASE: /home/ggfan/1-install/apache-tomcat-8.5.64
Using CATALINA_HOME: /home/ggfan/1-install/apache-tomcat-8.5.64
Using CATALINA_TMPDIR: /home/ggfan/1-install/apache-tomcat-8.5.64/temp
Using JRE_HOME: /home/ggfan/1-install/java/jdk1.8.0_271
Using CLASSPATH: /home/ggfan/1-install/apache-tomcat-8.5.64/bin/bootstrap.jar:/home/ggfan/1-install/apache-tomcat-8.5.64/bin/tomcat-juli.jar
Using CATALINA_OPTS: -javaagent:/home/ggfan/2-work/centuari-space/jdbc-leak-detector/target/jdbcld.jar=/home/ggfan/3-tmp/logs/jdbcld,INFO,org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
Tomcat started.
however, from tomcat log:
24-Sep-2021 15:45:04.437 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -javaagent:/home/ggfan/2-work/centuari-space/jdbc-leak-detector/target/jdbcld.jar=/home/ggfan/3-tmp/logs/jdbcld,INFO,org.apache.commons.dbcp.PoolingDataSource
inner class name after '$' sign get lost and the real argument received by my javaagent is the incomplete one.
what is wrong?
I am running with tomcat Apache Tomcat/8.5.64 on fedora 31
CodePudding user response:
In order to split CATALINA_OPTS
into words an pass them as arguments to java
, the catalina.sh
script uses eval
:
eval exec "\"$_RUNJAVA\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
...
this obviously performs variable expansion on $PoolGuardConnectionWrapper
. To prevent this escape the dollar sign twice:
export CATALINA_OPTS="${CATALINA_OPTS} ...PoolingDataSource\\\$PoolGuardConnectionWrapper"