bscott bscott - 11 months ago 60
Java Question

JVM System Property - how to treat as string literal

I have a Java application that uses -D system properties that I create. I'm having issues getting one of them to be translated correctly.

In my test environment (localhost) on my local computer, I'm running Windows using IntelliJ Idea IDE and I enter the -D system properties through the IDE like so:


I escape the double quotes because they need to be apart of the string literal. The above property works and the entire value including the curly braces is stored as a string literal.

The issue occurs when we deploy this application to our Linux cloud environment. I think the difference in architecture is causing the system property to not be read in correctly. In bash, I find the process ID of all the -D system properties and do a
ps -fwwp [processId]
command. I see that the above property is being broken up into a bunch of smaller properties that look like the following:



This is causing the part of my application that uses this property to fail. I've tried doing a bunch of escaping methods and none of them are working.

How can I escape this system property in such a way that the value is treated as the string literal

Answer Source

Bash requires the curly braces to be escaped, as in:


The other option is to try surrounding the entire string in single quotes. Bash won't do any expansions inside single quotes:


I don't know which option will be easier to make compatible with your windows environment.