Tomcat is configured with the path problem of generating gc logs

catalina.sh

JAVA_OPTS="-server -showversion -Xms10240m -Xmx10240m -XX:+PrintGC -XX:+PrintGCDetails  -XX:+PrintGCTimeStamps -XX:ParallelGCThreads=8 -XX:+UseConcMarkSweepGC -Xloggc:../logs/tomcat_gc.log" 

View

with jcmd
./jcmd  13735  VM.flags 
13735: 
-XX:CICompilerCount=4 -XX:InitialHeapSize=10737418240 -XX:MaxHeapSize=10737418240 -XX:MaxNewSize=697892864 -XX:MaxTenuringThreshold=6 -XX:MinHeapDeltaBytes=196608 -XX:NewSize=697892864 -XX:OldPLABSize=16 -XX:OldSize=10039525376 -XX:ParallelGCThreads=8 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseFastUnorderedTimeStamps -XX:+UseParNewGC 
After running

, it is found that there is no tomcat_gc.log
in the logs directory, but if you put

 -Xloggc:../logs/tomcat_gc.log
In

, there is no problem if you change / logs/tomcat_gc.log to an absolute path.
but I am under the bin path

  ls ../logs/

No problem.
what"s going on?

Mar.15,2021

first of all, the main cause of the problem is the difference between the current working directory and the executable location . You know, the current working directory in Linux is not the directory where the executable is located, but the current directory where the startup program is located.

for example, suppose you have a program current that prints out the current directory and it is in / home/user/script .

if you do this:

cd /home/user/script
./current

it will print out the working directory: / home/user/script/ but if you do:

cd /home/user/
script/current

the output working directory will be / home/user/

your configuration to start tomcat in different directories will have a completely different effect, such as this , the absolute path is the better choice.


the reason is as @ Yujiaao says, because of the relative path problem.
but it is also troublesome to move directories after using absolute paths. You can create a new setenv.sh file in the tomcat/bin directory and put these configurations in setenv.sh. In this file, you can use $CATALIAN_HOME to refer to the path started by tomcat. For example:

   

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3eaa6-409bb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3eaa6-409bb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?