The validator exploits Java's -XX:+PrintFlagsFinal
flag to build a symbol tree of all 700 or so legal -XX:
parameters and their types, including diagnostic or experimental parameters (if the user unlocks them in the evaluated command line).
The following kinds of parameters are currently supported:
- Virtually all -XX: parameters
- -Xmx / -Xms, including sizes (e.g.
-Xmx1g
) - -Dfoo=bar -- system properties with or without values.
Usage:
Clone the library, then build and publish it locally:
git clone https://github.com/hunam/jvmargs-validator.git
cd jvmargs-validator
sbt publish-local
In your own build.sbt:
libraryDependencies += "com.github.hunam"
Source usage:
import com.github.hunam.jvmargs.ArgsValidator
val validations = ArgsValidator.validate("java",
"-XX:+UseCompressedOops -Xmx100m -Dfoo.bar -XX:YakShaving=1000 -XX:MaxHeapSize=infinite")
val failures = validations filter (!_.successful)
failures foreach println
Prints:
[1.5] failure: unknown parameter
-XX:YakShaving=1000
^
[1.17] failure: 32-bit unsigned integer expected
-XX:MaxHeapSize=infinite
^
Known issues: many.
- The positioning information (e.g.,
[1.17]
) stands relative to the beginning of every argument - Many
-X
arguments aren't supported -classpath
,-version
, and other standard parameters haven't been implemented yet- Sometimes, validation failures provide errors that could be better
-Nadav.