对于通过
-D命令行上的标志设置的属性,您需要System.setProperty。例如:
System.setProperty("propname", "hello world");// ... later ...String value = System.getProperty("propname");更新:
您无法动态启用调试,但是可以在启动时启用调试,但稍后再附加调试器。通过以下操作,您可以侦听端口12345并立即开始运行程序(通过
suspend=n)。然后,您可以在需要时附加调试器,分离调试器,稍后再附加等。
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=12345
当然,即使没有连接调试器,这也会损害性能,因此它仅在开发/测试代码中有效,而在生产环境中则无法正常工作。为此,您需要记录日志,例如log4j。



