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.shbin/runbroker.shbin/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
runserver: Delete CMS/ParNew related parameters + switch GC log system + change memory
Reasons for deleting parameters:
UseConcMarkSweepGC(CMS) was marked deprecated in JDK9, completely removed in later versionsUseParNewGCis common young generation collector pairing in CMS eraUseCMSCompactAtFullCollectionis 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
| Symptom | Root Cause | Fix |
|---|---|---|
| Unrecognized VM option ‘UseConcMarkSweepGC’ or direct exit | JDK9+ removed/deprecated CMS/ParNew system parameters | Delete UseConcMarkSweepGC/UseParNewGC/UseCMSCompactAtFullCollection from runserver.sh |
| GC log parameter warning/not taking effect (-Xloggc, PrintGCDateStamps, etc.) | JDK9+ unified logging system migrated to -Xlog | Change -Xloggc to -Xlog:gc; delete old-style GC log parameters |
| Error: Could not find or load main class org.apache.rocketmq.namesrv.NamesrvStartup | CLASSPATH 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 JDK9 | Delete JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=..." |
| Invalid -XX:MetaspaceSize=… on JVM startup | Parameter unit/spelling error (e.g., 64mm) | Correct to -XX:MetaspaceSize=64m |
| Command still not found after setting environment variables | Script references inconsistent directories, variable names inconsistent | Check how bin scripts read HOME variable |