10

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.

Kevin Milner
  • 821
  • 2
  • 14
  • 30
  • 1
    Have you tried this https://stackoverflow.com/questions/8214392/passing-a-space-separated-system-property-via-a-shell-script-doesnt-work – mariusz2108 Jul 27 '17 at 16:48
  • https://stackoverflow.com/a/25551755/7605325 –  Jul 27 '17 at 16:51
  • 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! – Kevin Milner Jul 27 '17 at 17:10

3 Answers3

9

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

talex
  • 17,973
  • 3
  • 29
  • 66
  • 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? – S Kr Mar 05 '19 at 21:11
  • Try `MY_OVERIDES='$MY_OVERIDES -Dvar="a < b" ' ` – talex Mar 06 '19 at 06:03
  • That won't work, because `MY_OVERIDES` won't be expanded in single-quote strings. – Thomas Keller May 01 '19 at 10:32
  • Also, not related to Docker, but to Java and its crappy command line parsing: https://issues.jenkins-ci.org/browse/JENKINS-57271 – Thomas Keller May 01 '19 at 11:36
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.

Sree
  • 21
  • 3
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 '.' ...
Gerald Mücke
  • 10,724
  • 2
  • 50
  • 67