There is a requirement to run a Python application with Java runtime installed. This document provides a way of deploying Java runtime by the install-jdk library.
The install-jdk
library is a Python package that simplifies the process of installing OpenJDK on Windows, macOS, Linux, and others supported operating systems, saving time and effort. install-jdk
is a useful tool for users, developers, and system administrators who need to set up Java development environment or runtime in an automated and repeatable fashion.
install-jdk
has no third-party dependencies and depends solely on the standard libraries found in Python3. This means that you can easily install and use the library without having to install any additional dependencies.
install-jdk
aims to provide as many options as possible to install an OpenJDK Java version across a wide array of operating systems and architectures. Please see each vendors OpenJDK documentation to see what operating systems and architectures they support.
The Python buildpack supports dependency installation using PIP when a requirements.txt
file is included at the top level of your app’s directory.
We can include "install-jdk" in requirements.txt
file. Here is an example:
install-jdk
When pushing the apps into the TAS tile, you may notice the following lines generated during staging phrase.
Collecting install-jdk
Downloading install_jdk-1.1.0-py3-none-any.whl (15 kB)
...
Installing collected packages: packaging, MarkupSafe, itsdangerous, install-jdk, click, blinker, Werkzeug, Jinja2, gunicorn, Flask
Successfully installed Flask-3.1.0 Jinja2-3.1.5 MarkupSafe-3.0.2 Werkzeug-3.1.3 blinker-1.9.0 click-8.1.8 gunicorn-23.0.0 install-jdk-1.1.0 itsdangerous-2.2.0 packaging-24.2
After importing and installing JDK in python, we could see the OpenJDK installed successfully inside the container. This can be verified by printing out the Java version too.
>>> import sys
>>> sys.path.append('/home/vcap/deps/0/python/lib/python3.10/site-packages/')
>>> import jdk
>>> jdk.install('11')
'/home/vcap/.jdk/jdk-11.0.26+4'
...
vcap@####-####:~$ /home/vcap/.jdk/jdk-11.0.26+4/bin/java -version
openjdk version "11.0.26" 2025-01-21
OpenJDK Runtime Environment Temurin-11.0.26+4 (build 11.0.26+4)
OpenJDK 64-Bit Server VM Temurin-11.0.26+4 (build 11.0.26+4, mixed mode)
For more information about install-jdk, please refer to this link,