github.com/maier/nomad@v0.4.1-0.20161110003312-a9e3d0b8549d/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/exaple.jar"
    25      jvm_options = ["-Xmx2048m", "-Xms256m"]
    26    }
    27  }  
    28  ```
    29  
    30  The `java` driver supports the following configuration in the job spec:
    31  
    32  * `jar_path` - The path to the downloaded Jar. In most cases this will just be
    33    the name of the Jar. However, if the supplied artifact is an archive that
    34    contains the Jar in a subfolder, the path will need to be the relative path
    35    (`subdir/from_archive/my.jar`).
    36  
    37  * `args` - (Optional) A list of arguments to the Jar's main method. References
    38    to environment variables or any [interpretable Nomad
    39    variables](/docs/runtime/interpolation.html) will be interpreted before
    40    launching the task.
    41  
    42  * `jvm_options` - (Optional) A list of JVM options to be passed while invoking
    43    java. These options are passed without being validated in any way by Nomad.
    44  
    45  ## Examples
    46  
    47  A simple config block to run a Java Jar:
    48  
    49  ```hcl
    50  task "web" {
    51    driver = "java"
    52  
    53    config {
    54      jar_path    = "local/hello.jar"
    55      jvm_options = ["-Xmx2048m", "-Xms256m"]
    56    }
    57  
    58    # Specifying an artifact is required with the "java" driver. This is the
    59    # mechanism to ship the Jar to be run.
    60    artifact {
    61      source = "https://internal.file.server/hello.jar"
    62  
    63      options {
    64        checksum = "md5:123445555555555"
    65      }
    66    }
    67  }
    68  ```
    69  
    70  ## Client Requirements
    71  
    72  The `java` driver requires Java to be installed and in your system's `$PATH`. On
    73  Linux, Nomad must run as root since it will use `chroot` and `cgroups` which
    74  require root privileges. The task must also specify at least one artifact to
    75  download, as this is the only way to retrieve the Jar being run.
    76  
    77  ## Client Attributes
    78  
    79  The `java` driver will set the following client attributes:
    80  
    81  * `driver.java` - Set to `1` if Java is found on the host node. Nomad determines
    82  this by executing `java -version` on the host and parsing the output
    83  * `driver.java.version` - Version of Java, ex: `1.6.0_65`
    84  * `driver.java.runtime` - Runtime version, ex: `Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)`
    85  * `driver.java.vm` - Virtual Machine information, ex: `Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)`
    86  
    87  Here is an example of using these properties in a job file:
    88  
    89  ```hcl
    90  job "docs" {
    91    # Only run this job where the JVM is higher than version 1.6.0.
    92    constraint {
    93      attribute = "${driver.java.version}"
    94      operator  = ">"
    95      value     = "1.6.0"
    96    }
    97  }
    98  ```
    99  
   100  ## Resource Isolation
   101  
   102  The resource isolation provided varies by the operating system of
   103  the client and the configuration.
   104  
   105  On Linux, Nomad will attempt to use cgroups, namespaces, and chroot
   106  to isolate the resources of a process. If the Nomad agent is not
   107  running as root, many of these mechanisms cannot be used.
   108  
   109  As a baseline, the Java jars will be run inside a Java Virtual Machine,
   110  providing a minimum amount of isolation.