Java on Scalingo
Java is officially supported on Scalingo
Java Versions
Availability
The following Java versions are available:
Java SE Version | scalingo-20 | scalingo-22 |
---|---|---|
23 |
up to 23.0.1
|
up to 23.0.1
|
21 (LTS) |
up to 21.0.5
|
up to 21.0.5
|
17 (LTS) |
up to 17.0.13
|
up to 17.0.13
|
11 (LTS) |
up to 11.0.25
|
up to 11.0.24
|
8 (LTS) |
up to 1.8.0_432
|
up to 1.8.0_432
|
For Java SE 8, the JDK version is numbered 1.8
.
Selecting a Version
The default Java version on both scalingo-20
and scalingo-22
is the latest
1.8
. You can, however, instruct the platform to use another version.
To do so, specify the version number in a file called system.properties
,
which must be stored at the root of the project directory, like so:
java.runtime.version=<version>
Please replace <version>
with the actual number you want. For example, to
install the latest version of OpenJDK 15:
java.runtime.version=15
Frameworks
Most frameworks should work on the platform, the only condition is to listen on the port
defined by the environment variable PORT
- Spring Boot: You can find custom information about this framework at the following page
Languages Using the JVM
Even though the Java Virtual Machine (JVM) was initially designed to execute program developed with Java, a lot of new languages have been developed to be executed on it. Most of them should work on Scalingo. Here are examples of such languages known to work on Scalingo:
- Scala: see the specific documentation page here.
- Groovy: see the specific documentation page here.
- Clojure: see the specific documentation page here.
- Kotlin: see the sample deployed here, and the source code.
Deployment
It uses Maven 3.9.4 to build your application and OpenJDK 1.8 to run it (by default).
Example usage:
$ ls
Procfile pom.xml src
$ scalingo create my-app
$ git push scalingo master
...
-----> Java app detected
-----> Installing OpenJDK 1.8... done
-----> Installing Maven 3.3.9... done
-----> Installing settings.xml... done
-----> executing /app/tmp/repo.git/.cache/.maven/bin/mvn -B -Duser.home=/tmp/build_19z6l4hp57wqm -Dmaven.repo.local=/app/tmp/repo.git/.cache/.m2/repository -s /app/tmp/repo.git/.cache/.m2/settings.xml -DskipTests=true clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building readmeTest 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...
The buildpack will detect your app as Java if it has the file pom.xml
in the
root. It will use Maven to execute the build defined by your pom.xml
and
download your dependencies.
If your build results in a .war
file you need to add a small dependency to
your project in order to execute it. Just follow the guide.
The .m2
folder (local maven repository) will be cached between builds for
faster dependency resolution. However neither the mvn
executable nor the
.m2
folder will be available in your slug at runtime.
Configuration
Default JVM Configuration
By default the -Xmx
configuration of the JVM depends on the size of container
you selected for your application:
Container Size | Maximum Heap Size (MB) |
---|---|
S | 160 |
M | 300 |
L | 671 |
XL | 1536 |
2XL and above | ~80% of the RAM allocated in the plan |
Choose a Maven Version
The system.properties
file also allows for maven.version
entry
(regardless of whether you specify a java.runtime.version
entry). For example:
java.runtime.version=14
maven.version=3.2.5
Supported versions of Maven are:
- 3.0.5
- 3.1.1
- 3.2.5
- 3.3.9
- 3.5.4
- 3.6.2
- 3.9.4
You can request new versions of Maven by submitting a pull request to the Java
buildpack against the
lib/common.sh
file.
Customize Maven
There are two environment variables that can be used to customize the Maven execution:
-
MAVEN_CUSTOM_GOALS
: set toclean install
by default -
MAVEN_CUSTOM_OPTS
: set to-DskipTests=true
by default
These variables can be set like this:
$ scalingo env-set MAVEN_CUSTOM_GOALS="clean package"
$ scalingo env-set MAVEN_CUSTOM_OPTS="--update-snapshots -DskipTests=true"
Other options are available for defining custom a settings.xml
file.
Installation of JDK only (no Maven)
Your application may need to have the JDK/JVM only and not installing any dependency,
in this case you should use the multi-buildpack.
The .buildpacks
file lists the buildpacks you need to use, it has to look like:
https://github.com/Scalingo/buildpack-jvm-common
[Your second buildpack]
The role of the JVM Common buildpack to install it according to the
system.properties
file as mentionned above in this page.
Add a custom CA to Java Keychain
You may need to add one or multiple custom certificates to your JDK’s Keychain. You need to download Scalingo default JDK cacerts, then add the custom certificates you’d like to add with the following command:
keytool -import -keystore cacerts -file custom.cer
Then create the following directory in your application
.jdk-overlay/jre/lib/security/
and move the cacerts
keystore file to it.
Add it to your repository, and that’s it! Your custom CAs will be taken into
account.
Buildpack
More information at https://github.com/Scalingo/java-buildpack.