TL;DR

  • Scenario: RocketMQ 4.5.1 on JDK9+ startup blocked by “deprecated/removed JVM parameters” and “classpath not loading lib”.
  • Conclusion: Delete CMS/ParNew and java.ext.dirs, change GC log to -Xlog, CLASSPATH add ${BASE_DIR}/lib/*.
  • Output: runserver/runbroker/tools three-location minimum change checklist + version matrix + error quick reference.

RocketMQ Environment Setup

Software Download

cd /opt/software
wget https://archive.apache.org/dist/rocketmq/4.5.1/rocketmq-all-4.5.1-bin_release.zip

Extract and Move

unzip rocketmq-all-4.5.1-bin_release.zip
mv rocketmq-all-4.5.1-bin_release ../server/rocketmq

Script Modifications

Need to modify the following three files:

  • bin/runserver.sh
  • bin/runbroker.sh
  • bin/tools.sh

runserver

Modification content:

Delete the following parameters:

  • UseCMSCompactAtFullCollection
  • UseParNewGC
  • UseConcMarkSweepGC

Modify memory configuration:

JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=160m"

Modify GC configuration: Change -Xloggc to -Xlog:gc

CLASSPATH supplement:

export CLASSPATH=".:${BASE_DIR}/conf:${BASE_DIR}/lib/*"

broker

Modification content:

Modify JVM parameters:

-Xms256m -Xmx256m -Xmn128m

Delete the following parameters:

  • PrintGCDateStamps
  • PrintGCApplicationStoppedTime
  • PrintAdaptiveSizePolicy
  • UseGCLogFileRotation
  • NumberOfGCLogFiles=5
  • GCLogFileSize=30m

Delete:

JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib"

CLASSPATH supplement:

export CLASSPATH=".:${BASE_DIR}/conf:${BASE_DIR}/lib/*"

tools

Delete:

JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${BASE_DIR}/lib:${JAVA_HOME}/jre/lib/ext"

CLASSPATH supplement:

export CLASSPATH=".:${BASE_DIR}/conf:${BASE_DIR}/lib/*"

Explanation of Modifications

Reasons for deleting parameters:

  • UseConcMarkSweepGC (CMS) was marked deprecated in JDK9, completely removed in later versions
  • UseParNewGC is common young generation collector pairing in CMS era
  • UseCMSCompactAtFullCollection is Full GC compression control item within CMS system
  • JDK9 default GC has switched to G1

Change -Xloggc to -Xlog:gc: JDK9 introduced Unified JVM Logging (unified logging framework), GC logs also migrated to -Xlog system.

broker: Delete batch of old GC log parameters

Deleted parameters include:

  • PrintGCDateStamps
  • PrintGCApplicationStoppedTime
  • PrintAdaptiveSizePolicy
  • UseGCLogFileRotation
  • NumberOfGCLogFiles
  • GCLogFileSize

These all belong to “old GC log switches + old log rotation methods” from JDK8 and earlier. After JDK9+, all switched to -Xlog, these either get ignored or report deprecated/obsolete.

tools: Delete -Djava.ext.dirs=…

-Djava.ext.dirs relies on JRE’s extension classloader mechanism. This mechanism was removed in JDK9 due to modular runtime (JPMS); as long as this property is set, launcher may directly fail.


Environment Variables

vim /etc/profile
# RocketMQ Environment Variables
export ROCKET_HOME="/opt/server/rocketmq"
export PATH="${ROCKET_HOME}/bin:$PATH"

Refresh environment variables:

source /etc/profile

Start Services

NameServer

mqnamesrv

View logs:

tail -f ~/logs/rocketmqlogs/namesrv.log

Broker

mqbroker -n 0.0.0.0:9876

View logs:

tail -f ~/logs/rocketmqlogs/broker.log

Service Testing

Send Messages

Set environment variable:

export NAMESRV_ADDR=0.0.0.0:9876

Use official Demo:

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer

Receive Messages

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer

Error Quick Reference

SymptomRoot CauseFix
Unrecognized VM option ‘UseConcMarkSweepGC’ or direct exitJDK9+ removed/deprecated CMS/ParNew system parametersDelete UseConcMarkSweepGC/UseParNewGC/UseCMSCompactAtFullCollection from runserver.sh
GC log parameter warning/not taking effect (-Xloggc, PrintGCDateStamps, etc.)JDK9+ unified logging system migrated to -XlogChange -Xloggc to -Xlog:gc; delete old-style GC log parameters
Error: Could not find or load main class org.apache.rocketmq.namesrv.NamesrvStartupCLASSPATH doesn’t include ${BASE_DIR}/lib/*Solidify export CLASSPATH=".:${BASE_DIR}/conf:${BASE_DIR}/lib/*" into script
tools.sh Demo reports ClassNotFound / direct startup failure-Djava.ext.dirs=… relies on JRE ext mechanism, removed since JDK9Delete JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=..."
Invalid -XX:MetaspaceSize=… on JVM startupParameter unit/spelling error (e.g., 64mm)Correct to -XX:MetaspaceSize=64m
Command still not found after setting environment variablesScript references inconsistent directories, variable names inconsistentCheck how bin scripts read HOME variable