Documentation Contents
Java Platform, Standard Edition Deployment Guide
Contents    Previous    Next

15 Customizing JVM Options in Self-Contained Applications

This topic describes the UserJvmOptionsService API, which can be used in self-contained Java and JavaFX applications to alter the settings for the Java Virtual Machine (JVM). The new settings are used the next time that the application is started.

This topic contains the following sections:

15.1 Overview of the UserJvmOptionsService API

JVM options are used to configure the JVM. For example, options are available for managing memory, setting the class path, and turning on debugging. When you use the Java Packaging tools to package your self-contained application, you can pass in the JVM options that you want your application to use (-BjvmOptions), and provide default values for options that the user can set (-BuserJvmOptions).

The UserJvmOptionsService API enables you to provide a way to manage JVM options through the application, for example, by providing a preferences or settings feature. The settings specified by the user are used each time the application is started. If a user changes the settings, the application must be restarted to use the new settings.

When an application is launched, the values for JVM options are determined in the following order:

  • Options set through the UserJvmOptionsService API take precedence.

  • For options that are not set through the API, values from the -BuserJvmOptions arguments that were specified when the application package was created are used.

  • For options that are not set through the API or the -BuserJvmOptions arguments, values from the -BjvmOptions arguments that were specified when the application package was created are used.

  • For options that are not specified in any of the above locations, system values are used.

15.2 Using the UserJvmOptionsService API to Customize JVM Options

The UserJvmOptionsService API is available in the packager.jar file, which is in the java-home/lib directory. To use the UserJvmOptionsService API, include the packager.jar file in the bundle for your self-contained application.

The UserJvmOptionsService API includes the following methods:

15.2.1 Instantiating UserJvmOptionsService

The first step in using the UserJvmOptionsService API is to get an instance of the service to use. The instance is determined by the packager and the launcher. To get the correct instance, call UserJvmOptionsService.getUserJVMDefaults() in a command similar to the following example:

UserJvmOptionsService ujo=UserJvmOptionsService.getUserJVMDefaults();

Note:

Do not attempt to directly instantiate an instance of UserJvmOptions. Use only what is provided by the UserJvmOptions.getUserJVMDefaults() method.

Contents    Previous    Next

Oracle and/or its affiliates Copyright © 1993, 2015, Oracle and/or its affiliates. All rights reserved.
Contact Us