I am trying to execute a Maven exec command as follows:
mvn exec:java -Dexec.args="{\"parameters\":[{\"name\":\"parameter1\",\"value\":\"1\"}]}"
The argument is a JSON string which I need to process in my Java program. But when the string is read by the Java class, the double quotes are removed and it reads as:
{parameters:[{name:parameter1,value:1}]}
I have tried different escape sequences like \\
and \\\
, but it doesn't work. I need to preserve the double quotes in the string.
Could someone please help me resolve this?
Escaping double quotes in Java String If we try to add double quotes inside a String, we will get a compile-time error. To avoid this, we just need to add a backslash (/) before the double quote character. In this example, we want to print double quotes around the words “Steve” and “Java”. That's it!
Maven exec plugin allows us to execute system and Java programs from the maven command. There are two goals of the maven exec plugin: exec:exec - can be used to execute any program in a separate process. exec:java - can be used to run a Java program in the same VM.
try to use "
instead " (double quotes)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With