msopenJdk 11 on CentOS7 causes problems installing operating system openjdk package
The msopenjdk-11 from the packages-microsoft-com-prod yum repository provides java-11-openjdk-devel which causes problems for systems that require the standard java-11-openjdk-devel package layout as msopenjdk installs to different locations.
The partial yum provides listing below illustrates the issue:
>yum provides java-11-openjdk-devel
Loaded plugins: langpacks, priorities
...
1:java-11-openjdk-devel-11.0.19.0.7-1.el7_9.x86_64 : OpenJDK 11 Development Environment
Repo : updates-openlogic
...
msopenjdk-11-11.0.19-1.x86_64 : OpenJDK Development Kit 11 (JDK) with Hotspot by Microsoft
Repo : packages-microsoft-com-prod
Matched from:
Provides : java-11-openjdk-devel
When you do an installation of a package that depends on java-11-openjdk-devel you may get either implementation.
hey @MattCodd2, can you share a test case, perhaps using a container image?
I can describe what's needed to reproduce it, it's a bit of an odd one for a test case as all the interaction is at the OS level.
1/ Create a CentOS 7 vm (or docker image) 2/ Add this file to /etc/yum.repos.d: Filename: prod.repo Content:
[packages-microsoft-com-prod]
name=packages-microsoft-com-prod
baseurl=https://packages.microsoft.com/centos/7/prod/
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
3/ Execute the command
yum provides java-11-openjdk-devel
4/ Examine the output and note both the OS and the MS repo provide packages that satisfy that requirement
5/ Attempt to install the java-11-openjdk-devel package. From what I've seen it is fairly random which one gets installed
6/ Look at the files provided and the locations they install to for each package to see they are different
If I understand the problem as stated, it is that the Microsoft Build of OpenJDK satisfies the requirements of java-11-openjdk-devel but it doesn't install the specific tools to the same places as the RedHat OpenJDK 11 package. Is that correct?
Yes, that's the problem.
If you have systems with multiple versions of Java installed then you need to have some way of specifying a particular version is used for a specific application, and the OS build enables this by providing symlinks in /etc/alternatives that point to each version:
$ ls -ld /etc/alternatives/java /etc/alternatives/java_sdk*
lrwxrwxrwx 1 root root 73 May 4 21:10 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.el8_7.x86_64/jre/bin/java
lrwxrwxrwx 1 root root 60 May 4 21:11 /etc/alternatives/java_sdk -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.el8_7.x86_64
lrwxrwxrwx 1 root root 60 May 4 21:11 /etc/alternatives/java_sdk_1.8.0 -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.el8_7.x86_64
lrwxrwxrwx 1 root root 60 May 4 21:11 /etc/alternatives/java_sdk_1.8.0_openjdk -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.el8_7.x86_64
lrwxrwxrwx 1 root root 55 May 4 21:11 /etc/alternatives/java_sdk_11 -> /usr/lib/jvm/java-11-openjdk-11.0.19.0.7-1.el8_7.x86_64
lrwxrwxrwx 1 root root 55 May 4 21:11 /etc/alternatives/java_sdk_11_openjdk -> /usr/lib/jvm/java-11-openjdk-11.0.19.0.7-1.el8_7.x86_64
lrwxrwxrwx 1 root root 54 May 4 21:11 /etc/alternatives/java_sdk_17 -> /usr/lib/jvm/java-17-openjdk-17.0.7.0.7-1.el8_7.x86_64
lrwxrwxrwx 1 root root 54 May 4 21:11 /etc/alternatives/java_sdk_17_openjdk -> /usr/lib/jvm/java-17-openjdk-17.0.7.0.7-1.el8_7.x86_64
lrwxrwxrwx 1 root root 60 May 4 21:11 /etc/alternatives/java_sdk_openjdk -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.el8_7.x86_64
The Microsoft package only provides the basic symlink:
ls -ld /etc/alternatives/java /etc/alternatives/java_sdk*
ls: cannot access /etc/alternatives/java_sdk*: No such file or directory
lrwxrwxrwx. 1 root root 34 May 11 23:16 /etc/alternatives/java -> /usr/lib/jvm/msopenjdk-11/bin/java
which means that any code that uses the more specific symlinks to select particular versions fails.
The OS packages also create symlinks in /usr/lib/jvm along the same lines, which aren't replicated by the Microsoft package:
ls -l /usr/lib/jvm
total 0
lrwxrwxrwx 1 root root 26 May 9 11:34 java -> /etc/alternatives/java_sdk
lrwxrwxrwx 1 root root 29 May 9 11:34 java-11 -> /etc/alternatives/java_sdk_11
lrwxrwxrwx 1 root root 37 May 9 11:34 java-11-openjdk -> /etc/alternatives/java_sdk_11_openjdk
drwxr-xr-x 3 root root 17 Jul 19 2022 java-11-openjdk-11.0.14.0.9-1.el7_9.x86_64
drwxr-xr-x 3 root root 17 May 9 11:34 java-11-openjdk-11.0.15.0.9-2.el7_9.x86_64
drwxr-xr-x 8 root root 97 May 9 11:31 java-11-openjdk-11.0.19.0.7-1.el7_9.x86_64
lrwxrwxrwx 1 root root 34 May 9 11:34 java-openjdk -> /etc/alternatives/java_sdk_openjdk
lrwxrwxrwx 1 root root 21 May 9 11:34 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root 24 May 9 11:34 jre-11 -> /etc/alternatives/jre_11
lrwxrwxrwx 1 root root 32 May 9 11:34 jre-11-openjdk -> /etc/alternatives/jre_11_openjdk
lrwxrwxrwx 1 root root 42 May 9 11:31 jre-11-openjdk-11.0.19.0.7-1.el7_9.x86_64 -> java-11-openjdk-11.0.19.0.7-1.el7_9.x86_64
lrwxrwxrwx 1 root root 29 May 9 11:34 jre-openjdk -> /etc/alternatives/jre_openjdk
Where the actual packages install to wouldn't be a problem if these links were created
So the issue is that the Microsoft package does not contain the right set of symlinks to work properly with /etc/alternatives ?
Is this issue just observed in CentOS7? I have VMs for AZ DevOps agent-pool running Ubuntu-20.04, and I am getting an error: "Could not create the Java Virtual Machine". This is the jdk11 that came with the image:
openjdk version "11.0.19" 2023-04-18 LTS
OpenJDK Runtime Environment Microsoft-7621296 (build 11.0.19+7-LTS)
OpenJDK 64-Bit Server VM Microsoft-7621296 (build 11.0.19+7-LTS, mixed mode)
I installed the jdk using the JavaToolInstaller@0 taking the openjdk-11 from a storage:
- task: JavaToolInstaller@0
inputs:
versionSpec: '11'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'AzureStorage'
azureResourceManagerEndpoint: 'xxx'
azureStorageAccountName: 'yyy'
azureContainerName: 'jdkcontainer'
azureCommonVirtualFile: 'openjdk-11.0.2_linux-x64_bin.tar.gz'
And still the same error: "Could not create the Java Virtual Machine"
The package openjdk-11.0.2_linux-x64_bin.tar.gz is certainly not from Microsoft.
The package
openjdk-11.0.2_linux-x64_bin.tar.gzis certainly not from Microsoft.
Yes, I ran SonarQubeAnalyze@5 and it failed with the first jdk that came installed with the image. Then I tried force the jdk-11 installation with the JavaToolInstaller and still get the same error: "Could not create the Java Virtual Machine"
So the issue is that the Microsoft package does not contain the right set of symlinks to work properly with /etc/alternatives ?
Partly. Mainly that it doesn't provide the vendor independent symlinks so you cannot simply refer to java-11-openjdk regardless of which package is providing Java
Can you provide a detailed log of the error you get?
It's not really something that get logged. After installing OpenJDK 11 the expectation is that java can be accessed using
/etc/alternatives/java_sdk_11/bin/java
or
/usr/lib/jvm/java-11/bin/java
or any of the other symlinks mentioned above. The symlinks aren't created by the Microsoft openjdk package
@MattCodd2 your best option here is to extract the JDK into some folder like /opt/, then configure JAVA_HOME to point to the JDK installation directory, configure the $JAVA_HOME/bin in the PATH environment variable, and ensure that no other JDK is installed in the system.
What I described above is what a "manual" configuration looks like.