In Eclipse, when you specify arguments in the run dialog, Eclipse interprets ${foo}
as a request to use the Eclipse variable foo. I would like to pass a string 开发者_StackOverflow社区to my application that contains ${foo}
but Eclipse treats this as an undefined variable and gives me an error.
-Dfoo "bar" --pattern "regex magic ${foo}"
Eclipse does not accept the single quote (') as a quoting character, instead it becomes part of the input. Does anyone know how I can escape ${foo}
in this dialog so it is interpreted as text and not a variable reference?
${foo} by itself can be escaped with $"{foo}".
When ${foo} is already part of a doubly-quoted string, as in your question, I'm not sure how or if it can be escaped.
I do not think there is any way to do this in Eclipse.
The offending bit of code is org.eclipse.core.internal.variables.StringSubstitutionEngine#substitute.
This is the bit of code that substitutes the ${foo} with whatever you've defined foo to be. Unfortunately, it can cope with nested and concatenated variables, so if dollar="$" and rest="{foo}" then ${dollar}${rest} gives ${foo} which gets evaluated again.
For info, in the code reportUndefinedVariables is hardcoded as true further up the stack, which is why you're getting the error message. There doesn't seem to be any way of changing it.
You have to define a variable in Eclipse: name = dollar, value = $
(This can be done in the "run configuration" dialog, when you type your arguments, click "Variables...", and then click "Edit variables...", and add that variable).
Then, in the arguments text-box, type ${dollar}"{foo}"
精彩评论