Skip to content

Latest commit

 

History

History
67 lines (48 loc) · 3.45 KB

File metadata and controls

67 lines (48 loc) · 3.45 KB

Java Main Container

The Java Main Container allows an application that provides a class with a main() method to be run. The application is executed with a command of the form:

<JAVA_HOME>/bin/java -cp . com.gopivotal.SampleClass

Command line arguments may optionally be configured.

Detection Criteria Main-Class attribute set in META-INF/MANIFEST.MF, or java_main_class set in JBP_CONFIG_JAVA_MAIN
Tags java-main
Tags are printed to standard output by the buildpack detect script

If the application uses Spring, Spring profiles can be specified by setting the SPRING_PROFILES_ACTIVE environment variable. This is automatically detected and used by Spring. The Spring Auto-reconfiguration Framework will specify the cloud profile in addition to any others.

Spring Boot

If java_main_class is set to one of Spring Boot's launchers (JarLauncher, PropertiesLauncher or WarLauncher), the Java Main Container sets SERVER_PORT=$PORT so that the application binds to the CF-assigned port.

CF Tasks

The buildpack emits both web and task process types with the same command so cf run-task works without --command.

To run a task with a different main class (batch job, migration, etc.), set java_main_class to Spring Boot's PropertiesLauncher at staging time:

env:
  JBP_CONFIG_JAVA_MAIN: '{java_main_class: "org.springframework.boot.loader.launch.PropertiesLauncher"}'

Then override the main class per task at run time (requires CF CLI v7+):

cf run-task my-app --env JAVA_OPTS="-Dloader.main=com.example.BatchJob"

-Dloader.main is a Spring Boot PropertiesLauncher system property -- the buildpack passes it through to the JVM unchanged. JBP_CONFIG_JAVA_MAIN is a staging-time setting that applies to both web and task; -Dloader.main is a per-task runtime override.

Configuration

For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to Configuration and Extension.

The container can be configured using the JBP_CONFIG_JAVA_MAIN environment variable.

Name Description
arguments Optional command line arguments to be passed to the Java main class. The arguments are specified as a single YAML scalar in plain style or enclosed in single or double quotes.
java_main_class Optional Java class name to run. Values containing whitespace are rejected with an error, but all others values appear without modification on the Java command line. If not specified, the Java Manifest value of Main-Class is used. Setting this overrides container detection — even Spring Boot apps will use the Java Main container when this is set.

Example: PropertiesLauncher with external config

env:
  JBP_CONFIG_JAVA_MAIN: '{java_main_class: "org.springframework.boot.loader.launch.PropertiesLauncher", arguments: "--loader.home=/home/vcap/data"}'
  JAVA_OPTS: '-Dloader.path=/home/vcap/data/lib'