Java
Back to home
On this page
Note
You can now use composable image (BETA) to install runtimes and tools in your application container. To find out more, see the dedicated documentation page.
Java is a general-purpose programming language, and one of the most popular in the world today. Upsun supports Java runtimes that can be used with build management tools such as Gradle, Maven, and Ant.
Supported versions
You can select the major version. But the latest compatible minor version is applied automatically and can’t be overridden.
Patch versions are applied periodically for bug fixes and the like. When you deploy your app, you always get the latest available patches.
OpenJDK versions:
- 21
- 19
- 18
- 17
- 11
- 8
These versions refer to the headless packages of OpenJDK. To save space and reduce potential vulnerabilities, they don’t contain GUI classes, which can’t be used on the server.
Specify the language
To use Java, specify java
as your app’s type
:
applications:
# The app's name, which must be unique within the project.
<APP_NAME>:
type: 'java:<VERSION_NUMBER>'
For example:
applications:
# The app's name, which must be unique within the project.
myapp:
type: 'java:21'
Support build automation
Upsun supports the most common project management tools in the Java ecosystem, including:
Manage Maven versions
Java containers come with a version of Maven already installed. You may need to use a specific different version to manage your project. If the version you need differs from the version on your container, you can install the specific version that you need.
Add something like the following to your app configuration:
applications:
# The app's name, which must be unique within the project.
myapp:
type: 'java:21'
variables:
env:
MAVEN_VERSION: DESIRED_VERSION_NUMBER
hooks:
build: |
curl -sfLO "https://dlcdn.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz"
tar -zxf apache-maven-$MAVEN_VERSION-bin.tar.gz
export PATH="$PWD/apache-maven-$MAVEN_VERSION/bin:$PATH"
mvn --version
mvn clean package
Other JVM languages
It’s worth remembering that the JVM by its specification doesn’t read Java code, but bytecode. So within the JVM, it’s possible to run several languages. Upsun supports several of them, such as Kotlin, Groovy, and Scala, so long as that language works with any build automation that Upsun supports.
Article | Link |
---|---|
Kotlin and Spring | Source |
Scala and Spring | Source |
Note
While the table above shows examples for Platform.sh rather than for Upsun, the same rules apply with only slight changes in configuration.
Accessing services
You can access service credentials to connect to managed services from environment variables present in the application container. Consult each of the individual service documentation to see how to retrieve and surface credentials into your application.