我正在尝试将VisualVM与Spring应用程序结合使用。在配置端口时,这是可行的:
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=5006 \
-Dcom.sun.management.jmxremote.rmi.port=5006 -Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost \
-Dcom.sun.management.jmxremote.local.only=false -jar target/demo-0.0.1-SNAPSHOT.jar但在清理时,我尝试了这个,但这不起作用:
export JMX="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=5006 -Dcom.sun.management.jmxremote.rmi.port=5006 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.local.only=false"
java $JMX -jar target/demo-0.0.1-SNAPSHOT.jar应用程序启动了,但我无法连接,netstat没有列出打开的端口5006
一切都是一样的,除了长长的参数列表在一个变量中。如果我使用它而不是$JAVA_JMX,它可以工作:
$(echo "$JMX")为什么常规替换在这种情况下不起作用?而且肯定有更好的方法来解决这个问题。
demo-0.0.1-SNAPSHOT.jar只是我从他们的起始页面下载的一个未经修改的spring boot应用程序。
发布于 2021-05-03 22:49:55
您可以使用shell数组像这样使用它:
jmx=(-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=5006 -Dcom.sun.management.jmxremote.rmi.port=5006 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.local.only=false)
java "${jmx[@]}" -jar target/demo-0.0.1-SNAPSHOT.jarhttps://stackoverflow.com/questions/67370624
复制相似问题