Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping double quotes in exec java in Maven while executing through command line

Tags:

maven

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?

like image 393
user3465324 Avatar asked Aug 15 '14 10:08

user3465324


People also ask

How to escape double quotes in Java?

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!

What is exec Java in maven?

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.


1 Answers

try to use " instead " (double quotes)

like image 186
Anton Avatar answered Oct 20 '22 00:10

Anton