Upsun User Documentation

Java

Sign up

Get your free trial by clicking the link below.

Get your Upsun free trial

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 Anchor to this heading

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: Anchor to this heading

  • 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 Anchor to this heading

To use Java, specify java as your app’s type:

.upsun/config.yaml
applications:
    # The app's name, which must be unique within the project.
    <APP_NAME>:
        type: 'java:<VERSION_NUMBER>'

For example:

.upsun/config.yaml
applications:
    # The app's name, which must be unique within the project.
    app:
        type: 'java:21'

Support build automation Anchor to this heading

Upsun supports the most common project management tools in the Java ecosystem, including:

Manage Maven versions Anchor to this heading

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:

.upsun/config.yaml
applications:
    # The app's name, which must be unique within the project.
    app:
        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 Anchor to this heading

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

Accessing services Anchor to this heading

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.

Is this page helpful?