You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, there was no support for Java main() class applications.
This change adds the functionality required to run these kinds of
applications. In addition to the work required for that, the
opportunity was taken to refactor the code base to be more composable.
Specifically this includes the breaking out of JRE, container, and
framework components which are dynamically loaded and called based on
configuration. In addition to this, the documentation was
dramatically overhauled to describe how to configure and extend the
buildpack using the new structure.
[#49693913]
`java-buildpack` is a [Cloud Foundry][cf] buildpack for running Java applications
6
+
The `java-buildpack` is a [Cloud Foundry][cf] buildpack for running Java applications. It is designed to run most Java applications with no additional configuration, but supports configuration of the standard components, and extension to add custom components.
7
7
8
8
[cf]: http://www.cloudfoundry.com
9
9
10
-
# Buildpack Users
11
-
The buildpack allows you to configure the both the vendor and version of the Java runtime your application should use. To configure these, you can put a `system.properties` file into your pushed artifact.
* [Java Main Class Container](#javamain) ([Configuration](#javamain-config))
15
+
*[Extending](#extending)
16
+
* [JREs](#extending-jres)
17
+
* [Containers](#extending-containers)
12
18
13
-
## `system.properties`
14
-
If a `system.properties` file exists anywhere within your artifact's filesystem and the following properties have been set, they will be read and used to select the Java runtime for your application:
19
+
---
15
20
16
-
| Name | Description
17
-
| ---- | -----------
18
-
| `java.runtime.vendor` | The vendor of the Java runtime to use. The legal values are defined by the keys in [`config/jres.yml`][jres_yml].
19
-
| `java.runtime.version` | The version of the Java runtime to use. The legal values are defined by the keys in [`index.yml`][index_yml]
20
-
| `java.runtime.heap.size.maximum` | The Java maximum heap size to use. For example, a value of `64m` will result in the java command line option `-Xmx64m`. Values containing whitespace are rejected with an error, but all others values appear without modification on the java command line appended to `-Xmx`.
21
-
| `java.runtime.perm.gen.size.maximum` | The Java maximum PermGen size to use. For example, a value of `128m` will result in the java command line option `-XX:MaxPermSize=128m`. Values containing whitespace are rejected with an error, but all others values appear without modification on the java command line appended to `-XX:MaxPermSize=`.
22
-
| `java.runtime.stack.size` | The Java stack size to use. For example, a value of `256k` will result in the java command line option `-Xss256k`. Values containing whitespace are rejected with an error, but all others values appear without modification on the java command line appended to `-Xss`.
23
-
24
-
An example `system.properties` file would to contain the following:
25
-
```java
26
-
java.runtime.vendor=openjdk
27
-
java.runtime.version=1.7.0_21
21
+
# Usage
22
+
To use this buildpack specify the URI of the repository when pushing an application to Cloud Foundry.
The buildpack supports configuration and extension through the use of Git repository forking. The easiest way to accomplish this is to use [GitHub's forking functionality][fork] to create a copy of this repository. In that copy of the repository, make the required configuration and extension changes. Then when pushing a Cloud Foundry application, use the URL of the new repository. If the modifications are applicable to the Cloud Foundry community, please submit a [pull request][pull-request] with the changes.
Components are configured by setting key-value pairs in a `system.properties` file. The `system.properties` file can exist anywhere within the pushed artifact's file system.
37
+
38
+
# Design
39
+
The buildpack is designed as a collection of components. These components are divided into three types; _JREs_, _Containers_, and _Frameworks_.
40
+
41
+
### JRE Components
42
+
JRE components represent the JRE that will be used when running an application. This type of component is responsible for determining which JRE should be used, downloading and unpacking that JRE, and resolving any JRE-specific options that should be used at runtime.
43
+
44
+
Only a single JRE component can be used to run an application. If more than one JRE can be used, an error will be raised and application deployment will fail. In this case, the `java.runtime.vendor` property in `system.properties` must be set to a value that will cause a single JRE component to be used.
45
+
46
+
### Container Components
47
+
Container components represent the way that an application will be run. Container types range from traditional application servers and servlet containers to simple Java `main()` method execution. This type of component is responsible for determining which container should be used, downloading and unpacking that container, and producing the command that will be executed by Cloud Foundry at runtime.
48
+
49
+
Only a single container component can run an application. If more than one container can be used, an error will be raised and application deployment will fail.
50
+
51
+
### Framework Components
52
+
Framework components represent additional behavior or transformations used when an application is run. Framework types include the downloading of JDBC JARs for bound services and automatic reconfiguration of `DataSource`s in Spring configuration to match bound services. This type of component is responsible for determining which frameworks are required, transforming the application, and contributing any additional options that should be used at runtime.
53
+
54
+
Any number of framework components can be used when running an application.
55
+
56
+
# Standard Components
57
+
The buildpack contributes a number of standard components that enable most Java applications to run.
58
+
59
+
<aname='openjdk'></a>
60
+
## OpenJDK JRE
61
+
**Criteria:**`java.runtime.vendor` set to `openjdk`
62
+
63
+
The OpenJDK JRE provides Java runtimes from the [OpenJDK][openjdk] project. Versions of Java from the 1.6, 1.7, and 1.8 lines are available. If the version to use is not configured in `system.properties`, the latest version from the `1.7.0` line is chosen.
64
+
65
+
[openjdk]: http://openjdk.java.net
66
+
67
+
### JRE Version Syntax and Ordering
30
68
JREs versions are composed of major, minor, micro, and optional qualifier parts (`<major>.<minor>.<micro>[_<qualifier>]`). The major, minor, and micro parts must be numeric. The qualifier part is composed of letters, digits, and hyphens. The lexical ordering of the qualifier is:
31
69
32
70
1. hyphen
33
71
2. lowercase letters
34
72
3. uppercase letters
35
73
4. digits
36
74
37
-
## JRE Version Wildcards
75
+
###JRE Version Wildcards
38
76
In addition to declaring a specific version of JRE to use, you can also specify a bounded range of JRES to use. Appending the `+` symbol to a version prefix chooses the latest JRE that begins with the prefix.
39
77
40
78
| Example | Description
@@ -43,51 +81,110 @@ In addition to declaring a specific version of JRE to use, you can also specify
43
81
| `1.7.+` | Selects the greatest available version less than `1.8.0`.
44
82
| `1.7.0_+` | Selects the greatest available version less than `1.7.1`. Use this syntax to stay up to date with the latest security releases in a particular version.
45
83
46
-
## Default JRE
47
-
If the user does not specify a JRE vendor and version, a JRE is selected automatically. The selection algorithm is as follows:
84
+
<aname='openjdk-config'></a>
85
+
### Configuration
86
+
The OpenJDK JRE allows the configuration of the version of Java to use as well as the allocation of memory at runtime.
48
87
49
-
1. If a single vendor is available, it is selected. If zero or more than one vendor is available, the buildpack will fail.
50
-
2. The latest version of JRE for the selected vendor is chosen.
| `java.runtime.version` | The version of Java runtime to use. This value can either be an explicit version as found in [this listing][index_yml] or by using wildcards.
55
93
56
-
# Buildpack Developers
57
-
This buildpacks is designed to be extensible by other developers. To this end, various bits of configuration are exposed that make it simple to add functionality.
By default, this buildpack only allows users to choose from [OpenJDK][openjdk] JREs. To allow users to choose a JRE from other vendors, these vendors must be specified in [`config/jres.yml`][jres_yml]. The file is [YAML][yaml] formatted and in the simplest case is a mapping from a vendor name to a `String` repository root.
96
+
#### Memory
61
97
62
-
```yaml
63
-
<vendor name>: <JRE repository root URI>
64
-
```
98
+
| Name | Description
99
+
| ---- | -----------
100
+
| `java.heap.size` | The Java maximum heap size to use. For example, a value of `64m` will result in the java command line option `-Xmx64m`. Values containing whitespace are rejected with an error, but all others values appear without modification on the java command line appended to `-Xmx`.
101
+
| `java.permgen.size` | The Java maximum PermGen size to use. For example, a value of `128m` will result in the java command line option `-XX:MaxPermSize=128m`. Values containing whitespace are rejected with an error, but all others values appear without modification on the java command line appended to `-XX:MaxPermSize=`.
102
+
| `java.stack.size` | The Java stack size to use. For example, a value of `256k` will result in the java command line option `-Xss256k`. Values containing whitespace are rejected with an error, but all others values appear without modification on the java command line appended to `-Xss`.
65
103
66
-
When configured like this, if the user does not specify a version of the JRE to use, the latest possible version will be selected. If a particular JRE should use a default that is not the latest (e.g. using `1.7.0_21` instead of `1.8.0_M7`), the default version can be specified by using a `Hash` instead of a `String` as the value.
104
+
<aname='javamain'></a>
105
+
## Java Main Class Container
106
+
**Criteria:**`Main-Class` attribute set in `META-INF/MANIFEST.MF` or `java.main.class` set
67
107
68
-
```yaml
69
-
<vendor name>:
70
-
default_version: <default version pattern>
71
-
repository_root: <JRE repository root URI>
72
-
```
108
+
The Java Main Class Container allows applications that provide a class with a `main()` method in it to be run. These applications are run with a command that looks like `./java/bin/java -cp . com.gopivotal.SampleClass`.
73
109
74
-
The JRE repository root must contain a `/index.yml` file ([example][index_yml]). This file is also [YAML][yaml] formatted with the following syntax:
110
+
<aname='javamain-config'></a>
111
+
### Configuration
75
112
76
-
```yaml
77
-
<JRE version>: <path relative to JRE repository root>
113
+
| Name | Description
114
+
| ---- | -----------
115
+
| `java.main.class` | The 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.
116
+
117
+
118
+
# Extending
119
+
The buildpack is designed to be extended by specifying components in [`config/components.yml`][components_yml]. The values listed in this file correspond to Ruby class names that will be instantiated and called. In order for these classes to be instantiated, the files containing them must be located in specific directories in the repository.
120
+
121
+
[components_yml]: config/components.yml
122
+
123
+
<aname='extending-jres'></a>
124
+
## JREs
125
+
To add a JRE, the class file must be located in [`lib/java_buildpack/jre`][jre_dir]. The class must have the following methods:
126
+
127
+
[jre_dir]: lib/java_buildpack/jre
128
+
129
+
```ruby
130
+
# An initializer for the instance.
131
+
#
132
+
#@param[Hash<Symbol, String>] context A shared context provided to all components
133
+
#@optioncontext[String] :app_dir the directory that the application exists in
134
+
#@optioncontext[Array<String>] :java_opts an array that Java options can be added to
135
+
#@optioncontext[Hash] :system_properties the properties provided by the user
136
+
definitialize(context= {})
137
+
138
+
# Determines if the JRE can be used to run the application.
139
+
#
140
+
#@return[String, nil] If the JRE can be used to run the application, a +String+ that uniquely identifies the JRE
0 commit comments