Skip to content

hunam/jvmargs-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

jvmargs-validator

A Java VM command-line arguments validator implemented in Scala

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:

  1. Virtually all -XX: parameters
  2. -Xmx / -Xms, including sizes (e.g. -Xmx1g)
  3. -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.

  1. The positioning information (e.g., [1.17]) stands relative to the beginning of every argument
  2. Many -X arguments aren't supported
  3. -classpath, -version, and other standard parameters haven't been implemented yet
  4. Sometimes, validation failures provide errors that could be better

-Nadav.

About

JVM command line arguments validator, implemented in Scala

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages