Search code examples
javawindowswinrun4j

On Windows with Winrun4j how do I specify Java gclog location that understands APPDATA location


I want to enable garbage collection logging for Java application running on Windows

Like standard Windows programs the application is installed in C:/Program Files/CompanyName/SoftwareName and my application logs are stored in C:/Users/username/Roaming/SoftwareName

and in my code I identify the location of C:/Users/username/AppData with

System.getenv("APPDATA");

Now I want the garbage logs to also go in that location, but I cannot see how I could specify that.

Also problematically if i just specify a filename and try to create in C:/Program Files/CompanyName/SoftwareName instead with

-Xlog:gc*:file=gc.log:time:filecount=7,filesize=8M

then JVM fails to start because on Windows programs do not have permissions to create files in this folder after installation

Now if i was starting application in a batch script I suppose I could use %APPDATA% in the batch but I am using winrun4j so I do not see I have access to such variables from the .ini file.


Solution

  • Okay I found I could use %APPDATA% in the .ini file as well

    e.g

    vmarg.1=-Xlog:gc*:file=%APPDATA%\SoftwareName\Logs\gc.log:time:filecount=7,filesize=2M