Search code examples
javawindowsloggingjava-9

How to use a Windows filename with a colon with Java 9 unified logging?


% java11 -Xlog:gc*:file=c:\max.txt -version
[0.002s][error][logging] Invalid decorator '\max.txt'.
Invalid -Xlog option '-Xlog:gc*:file=c:\max.txt', see error log for 
details.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Apparently with Java 9 (and later) unified logging a colon is used as a separator between fields in the -Xlog arguments. So, how do I specify a Windows pathname that has a colon in it? Is there an escape of some kind? If I specify the filename as is, I get the error I included above. Thank you.


Solution

  • One of the ways suggested for solving that on the mailing list is using shell escapes like:

    java -Xlog:gc*:file=\"C:\max.txt\" -version
    

    Note that according to Dave Holmes' posting, only double quotes are supported. Depending on the shell, the escaping is necessary so that the Java command sees the quotes.