passing Jvm properties (via -D) that contain spaces
Asked Answered
S

3

12

I have a docker application that runs a java jar inside from the command line. I have set up the docker container to pass through "other java options", and in this case I would like to pass the following:

jdk.certpath.disabledAlgorithms=MD2, MD5, RSA keySize < 128, DSA keySize < 128, EC keySize < 128

I was hoping to be able to pass it in via -Djdk.etc but the spaces seem to really throw things off. With the spaces java complains it doesn't know what to do with the MD5 and later ("Error: Could not find or load main class MD5,". Without the spaces, I get errors about keySize< being an unknown main class.

Can someone please help me with the proper way to pass this parameter in? I have tried surrounding the whole thing in quotes yet the results are the same.

Scalping answered 27/7, 2017 at 16:34 Comment(3)
Have you tried this #8214892Taconite
https://mcmap.net/q/1010344/-how-to-pass-list-of-arguments-to-vm-command-lineConventioner
man I looked up and down SO for anything resembling my question. Sorry! I put in both @talex's answer and the accepted answer in the link mariusz2108 commented, and it seems to all be resolved. Thanks!Scalping
H
11

You should surround only variable value. -Dvar="a < b" works for me.

Holmun answered 27/7, 2017 at 16:48 Comment(4)
All my -D properties are inside a UNIX variable, i tried using MY_OVERIDES="$MY_OVERIDES -Dvar=\"a < b\" " It doesn't work after that. When i echo $MY_OVERRIDES, it looks ok. What to do here?Expostulatory
Try MY_OVERIDES='$MY_OVERIDES -Dvar="a < b" ' Holmun
That won't work, because MY_OVERIDES won't be expanded in single-quote strings.Assumptive
Also, not related to Docker, but to Java and its crappy command line parsing: issues.jenkins-ci.org/browse/JENKINS-57271Assumptive
H
1

Found a better explanation here: http://mail.openjdk.java.net/pipermail/jmh-dev/2015-March/001768.html

The two options suggested were.

$ java -jar benchmarks.jar -jvmArgs "-Dx=12 -Dy=\"one two\""
$ java -jar benchmarks.jar -jvmArgs "-Dx=12" -jvmArgs "-Dy=one two"

Tried the 2nd version with Maven too. It's working.

Highhanded answered 11/8, 2020 at 19:28 Comment(0)
O
0

Newer versions of java (Idk since when, but at least it works with jdk17) allow passing argument files (using '@') containing the jvm options instead of adding the jvm options directly

echo '-Djdk.certpath.disabledAlgorithms="MD2, MD5, RSA keySize < 128, DSA keySize < 128, EC keySize < 128"' > /opt/jvmargs

java @/opt/jvmargs -Dother=arg -cp '.' ...
Orndorff answered 24/11, 2022 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.