github.com/smintz/nomad@v0.8.3/website/source/docs/drivers/java.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Drivers: Java"
     4  sidebar_current: "docs-drivers-java"
     5  description: |-
     6    The Java task driver is used to run Jars using the JVM.
     7  ---
     8  
     9  # Java Driver
    10  
    11  Name: `java`
    12  
    13  The `java` driver is used to execute Java applications packaged into a Java Jar
    14  file. The driver requires the Jar file to be accessible from the Nomad
    15  client via the [`artifact` downloader](/docs/job-specification/artifact.html).
    16  
    17  ## Task Configuration
    18  
    19  ```hcl
    20  task "webservice" {
    21    driver = "java"
    22  
    23    config {
    24      jar_path    = "local/example.jar"
    25      jvm_options = ["-Xmx2048m", "-Xms256m"]
    26    }
    27  }  
    28  ```
    29  
    30  The `java` driver supports the following configuration in the job spec:
    31  
    32  * `class` - (Optional) The name of the class to run. If `jar_path` is specified
    33    and the manifest specifies a main class, this is optional. If shipping classes
    34    rather than a Jar, please specify the class to run and the `class_path`.
    35  
    36  * `class_path` - (Optional) The `class_path` specifies the class path used by
    37    Java to lookup classes and Jars.
    38  
    39  * `jar_path` - (Optional) The path to the downloaded Jar. In most cases this will just be
    40    the name of the Jar. However, if the supplied artifact is an archive that
    41    contains the Jar in a subfolder, the path will need to be the relative path
    42    (`subdir/from_archive/my.jar`).
    43  
    44  * `args` - (Optional) A list of arguments to the Jar's main method. References
    45    to environment variables or any [interpretable Nomad
    46    variables](/docs/runtime/interpolation.html) will be interpreted before
    47    launching the task.
    48  
    49  * `jvm_options` - (Optional) A list of JVM options to be passed while invoking
    50    java. These options are passed without being validated in any way by Nomad.
    51  
    52  ## Examples
    53  
    54  A simple config block to run a Java Jar:
    55  
    56  ```hcl
    57  task "web" {
    58    driver = "java"
    59  
    60    config {
    61      jar_path    = "local/hello.jar"
    62      jvm_options = ["-Xmx2048m", "-Xms256m"]
    63    }
    64  
    65    # Specifying an artifact is required with the "java" driver. This is the
    66    # mechanism to ship the Jar to be run.
    67    artifact {
    68      source = "https://internal.file.server/hello.jar"
    69  
    70      options {
    71        checksum = "md5:123445555555555"
    72      }
    73    }
    74  }
    75  ```
    76  
    77  A simple config block to run a Java class:
    78  
    79  ```hcl
    80  task "web" {
    81    driver = "java"
    82  
    83    config {
    84      class       = "Hello"
    85      class_path  = "${NOMAD_TASK_DIR}"
    86      jvm_options = ["-Xmx2048m", "-Xms256m"]
    87    }
    88  
    89    # Specifying an artifact is required with the "java" driver. This is the
    90    # mechanism to ship the Jar to be run.
    91    artifact {
    92      source = "https://internal.file.server/Hello.class"
    93  
    94      options {
    95        checksum = "md5:123445555555555"
    96      }
    97    }
    98  }
    99  ```
   100  
   101  ## Client Requirements
   102  
   103  The `java` driver requires Java to be installed and in your system's `$PATH`. On
   104  Linux, Nomad must run as root since it will use `chroot` and `cgroups` which
   105  require root privileges. The task must also specify at least one artifact to
   106  download, as this is the only way to retrieve the Jar being run.
   107  
   108  ## Client Attributes
   109  
   110  The `java` driver will set the following client attributes:
   111  
   112  * `driver.java` - Set to `1` if Java is found on the host node. Nomad determines
   113  this by executing `java -version` on the host and parsing the output
   114  * `driver.java.version` - Version of Java, ex: `1.6.0_65`
   115  * `driver.java.runtime` - Runtime version, ex: `Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)`
   116  * `driver.java.vm` - Virtual Machine information, ex: `Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)`
   117  
   118  Here is an example of using these properties in a job file:
   119  
   120  ```hcl
   121  job "docs" {
   122    # Only run this job where the JVM is higher than version 1.6.0.
   123    constraint {
   124      attribute = "${driver.java.version}"
   125      operator  = ">"
   126      value     = "1.6.0"
   127    }
   128  }
   129  ```
   130  
   131  ## Resource Isolation
   132  
   133  The resource isolation provided varies by the operating system of
   134  the client and the configuration.
   135  
   136  On Linux, Nomad will attempt to use cgroups, namespaces, and chroot
   137  to isolate the resources of a process. If the Nomad agent is not
   138  running as root, many of these mechanisms cannot be used.
   139  
   140  As a baseline, the Java jars will be run inside a Java Virtual Machine,
   141  providing a minimum amount of isolation.