Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Java 17 on Yocto OS

My colleagues and I are trying to build a Yocto OS Image. Our application consists of several Micro-Services written with Java 17 and they require to run on an embedded device (phyCORE i.MX 8M Plus Setup Guide). On another System we would run them within Docker containers and deploy them this way but since none of us have ever worked on a Yocto build before, we are kinda stuck getting things to work and finding the layers we have to add to the Yocto build.

We did get the meta-java layer to install but that is only based on openjdk-8.

The following files are the current build configuration

local.conf

MACHINE ?= "phyboard-pollux-imx8mp-3"

DISTRO ?= "ampliphy-vendor"

########################
# global configuration #
########################

# That are the default values of bitbake.  Adapt these to your workspace and
# host preferences.
#DL_DIR = "${TOPDIR}/downloads"
#SSTATE_DIR = "${TOPDIR}/sstate-cache"

# License Handling
#  - Uncomment for i.MX6 proprietary GPU libraries
#LICENSE_FLAGS_WHITELIST += "license-nxp_v14-june-2016_imx-gpu-viv"
#  - Uncomment for Freescale i.MX6 VPU firmware blobs
#LICENSE_FLAGS_WHITELIST += "license-freescale_v12-march-2016_firmware-imx"

# build artifacts are deployed here
DEPLOY_DIR = "${TOPDIR}/deploy"

# enable bitbakes git shallow functionality: this reduces download volume
# from 7.3G to 1.6 G as of sumo. If you need the git history of a project,
# you can run a "git remote update" in the tmp dir, as the remotes are
# correctly specified
BB_GIT_SHALLOW = "1"

# Select configuration UI for linux and barebox recipe. The openembedded
# default is 'menuconfig', 'nconfig' has more features.
# busybox only supports menuconfig
#KCONFIG_CONFIG_COMMAND = "menuconfig"
KCONFIG_CONFIG_COMMAND = "nconfig"
KCONFIG_CONFIG_COMMAND_pn-busybox = "menuconfig"

# SDK will be build for that cpu
#SDKMACHINE ?= "x86_64"

# bitbake disk monitor setup
BB_DISKMON_DIRS ??= "\
    STOPTASKS,${TMPDIR},1G,100K \
    STOPTASKS,${DL_DIR},1G,100K \
    STOPTASKS,${SSTATE_DIR},1G,100K \
    STOPTASKS,/tmp,100M,100K \
    ABORT,${TMPDIR},100M,1K \
    ABORT,${DL_DIR},100M,1K \
    ABORT,${SSTATE_DIR},100M,1K \
    ABORT,/tmp,10M,1K"

#######################
# Image configuration #
#######################

# The following line disables the autostart of the phytec-qtdemo by
# default, but you can start the demo anytime using
#  $ systemctl start phytec-qtdemo.service
#SYSTEMD_AUTO_ENABLE_pn-phytec-qtdemo = "disable"

# You can disable and enable FSTYPES as you wish. e.g. 'ext4'.
# This variable is ordering dependend.
#IMAGE_FSTYPES = "tar.gz wic ubifs emmc"

# To change the variable for any imx8 machine:
#IMAGE_FSTYPES_mx8 = "tar.gz wic ubifs emmc"

# Turn on debugging options of the kernel
#DEBUG_BUILD_pn-linux-mainline = "1"
# Turn on debugging options of the imx kernel
#DEBUG_BUILD_pn-linux-imx = "1"
# Turn on debugging options of the barebox
#DEBUG_BUILD_pn-barebox = "1"

# Include kernel sources in SDK
TOOLCHAIN_TARGET_TASK_append = " kernel-devsrc"

# The default package class of the distro ampliphy is 'package_ipk'. The first
# value is used as the package manager to build the image and sdk. To build
# also tar packages use
#PACKAGE_CLASSES = "package_ipk package_tar"

# Variable IMAGE_ROOTFS_EXTRA_SPACE from poky/meta/conf/documentation.conf:
#   Defines additional free disk space created in the image in Kbytes. By
#   default, this variable is set to '0'.
# This example line adds an additional 512 MiB of free space to the root
# filesystem:
#IMAGE_ROOTFS_EXTRA_SPACE = "524288"

# See http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#ref-features-image
#    Through these variables, you can add several different predefined
#    packages such as development utilities or packages with debug information
#    needed to investigate application problems or profile applications
EXTRA_IMAGE_FEATURES = ""
# - "Makes an image suitable for development (e.g. allows root logins without
#    passwords and enables post-installation logging)"
EXTRA_IMAGE_FEATURES += "debug-tweaks"
# - "Installs debug symbol packages for all packages installed in a given
#    image."
#EXTRA_IMAGE_FEATURES += "dbg-pkgs"
# - "Installs debugging tools such as strace and gdb."
#EXTRA_IMAGE_FEATURES += "tools-debug"

######################
# rauc configuration #
######################

# certificate location for signing bundles
#CERT_PATH = "${TOPDIR}/../sources/meta-ampliphy/openssl-ca"

####################
# QT configuration #
####################

# We disable qt widgets per default to save about 10 MB of storage. If
# you need qt widget support, you can enable it with this line
#DISTRO_FEATURES_append = " qtwidgets"

CONF_VERSION = "1"

# Uncomment to accept NXP EULA (needed, if any NXP / freescale layer is used)
# EULA can then be found under ../sources/meta-freescale/EULA
ACCEPT_FSL_EULA = "1"

# A TISDK BSP requires per default an external toolchain
# Provide a default path that is compatible to our TISDK docker image
TOOLCHAIN_BASE ?= "/opt/PHYTEC_BSPs"

############################################
# Addition of openjdk-8 and minicom to the default build
PREFERRED_PROVIDER_virtual/java-initial-native = "cacao-initial-native"
PREFERRED_PROVIDER_virtual/java-native = "jamvm-native"
PREFERRED_PROVIDER_virtual/javac-native = "ecj-bootstrap-native"

IMAGE_INSTALL_append = " minicom openjdk-8"
############################################

bblayers.conf

# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

OEROOT := "/home/ubuntu/yocto/sources/poky"
# add BSPDIR variable, as it is needed by recipes of NXP
BSPDIR := "${OEROOT}/../.."

#######################################
# IMPORTANT NOTE: change to correct location and username on your build!
MYBSPDIR := "/home/ubuntu/yocto/sources"
########################################

# In our BSPs active layers are defined by the manifest.xml for all BSPs. The
# bblayers.conf gets created by the init_bblayers.py script.
BBLAYERS ?= ""
BBLAYERS += "\
  ${OEROOT}/../poky/meta \
  ${OEROOT}/../poky/meta-poky \
  ${OEROOT}/../meta-openembedded/meta-oe \
  ${OEROOT}/../meta-openembedded/meta-networking \
  ${OEROOT}/../meta-openembedded/meta-python \
  ${OEROOT}/../meta-openembedded/meta-multimedia \
  ${OEROOT}/../meta-openembedded/meta-filesystems \
  ${OEROOT}/../meta-openembedded/meta-perl \
  ${OEROOT}/../meta-openembedded/meta-gnome \
  ${OEROOT}/../meta-imx/meta-bsp \
  ${OEROOT}/../meta-imx/meta-sdk \
  ${OEROOT}/../meta-imx/meta-ml \
  ${OEROOT}/../meta-browser/meta-chromium \
  ${OEROOT}/../meta-clang \
  ${OEROOT}/../meta-freescale \
  ${OEROOT}/../meta-freescale-3rdparty \
  ${OEROOT}/../meta-freescale-distro \
  ${OEROOT}/../meta-nxp-demo-experience \
  ${OEROOT}/../meta-python2 \
  ${OEROOT}/../meta-qt5 \
  ${OEROOT}/../meta-virtualization \
  ${OEROOT}/../meta-rauc \
  ${OEROOT}/../meta-phytec \
  ${OEROOT}/../meta-ampliphy \
  ${OEROOT}/../meta-security \
  ${OEROOT}/../meta-security/meta-tpm \
  "
###################################
# Addition of the meta-java layer
BBLAYERS += "${MYBSPDIR}/meta-java"
###################################

We also tried creating and adding a Custom Layer containing openjdk-17 but that failed in the cross-compiling process started via bitbake <recipe-name> within the do_configure() part.

Is there any existing layer that we can add using a newer Java version than version 8 or are there any tips on how to get a Custom Layer running?

like image 630
bc_tom Avatar asked Oct 19 '25 01:10

bc_tom


1 Answers

I have had the same issue but i have solved it by creating my own layer that leverages from the Adoptium and Eclipse Temurin projects. It takes a prebuilt JRE and includes it in your OE/Yocto build. Btw, that is way faster than building the whole JRE on your own.

You can use my layer by adding it to your bblayers.conf and then append openjdk-17-jre to your IMAGE_INSTALL in your local.conf file. My layer currently supports JREs for ARM, ARM64 and x86_64 architecture.

Make sure your setup is using at least the dunfell codename/branch of OE/Yocto. You can have a look at the documentation of the Yocto project on how to migrate.

For everyone wondering why the official java layer meta-java seems to be stuck on version 8 of OpenJDK: Building and maintaining a JVM is much work. Furthermore in order to compile the desired version of a JVM, you need a bootstraping JVM of the previous version. E.g. by building OpenJDK 11 JRE you need OpenJDK 10 JDK. As i said, it is a lot of work.

like image 94
Sebastian Veit Avatar answered Oct 21 '25 15:10

Sebastian Veit