question

CHEKOORJaya-3067 avatar image
0 Votes"
CHEKOORJaya-3067 asked TakahitoIwasa answered

How to downgrade Java version default installed into Azure Portal from Java 17 to Java 11

Java Maven compatibility issues. Java version 17 and Maven version 3.6 is the default versions in my Azure CLI.
Steps to replicate

  1. Login to azure portal

  2. Click on the Azure CLI icon

  3. Azure CLI poweshell terminal opens up

  4. Type mvn -X

  5. Following error is displayed.

  6. After much googling, my understanding is that Maven 3.6 works with Java 11 but has issues with Java 17. Currently , if change Azure CLI to bash terminal and type env, it shows JAVA_HOME as JAVA_HOME=/usr/lib/jvm/msopenjdk-17-amd64. How can I change it to Java 11?

    Error:



PS /home/jaya> mvn -X
Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 17.0.2, vendor: Microsoft, runtime: /usr/lib/jvm/msopenjdk-17-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-1078-azure", arch: "amd64", family: "unix"
[ERROR] Error executing Maven.
com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: Unable to load cache item
at com.google.common.cache.LocalCache$Segment.get (LocalCache.java:2205)
at com.google.common.cache.LocalCache.get (LocalCache.java:3951)
at com.google.common.cache.LocalCache.getOrLoad (LocalCache.java:3955)
at com.google.common.cache.LocalCache$LocalLoadingCache.get (LocalCache.java:4870)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked (LocalCache.java:4876)
at com.google.inject.internal.FailableCache.get (FailableCache.java:51)
at com.google.inject.internal.ConstructorInjectorStore.get (ConstructorInjectorStore.java:48)
at com.google.inject.internal.ConstructorBindingImpl.initialize (ConstructorBindingImpl.java:155)
at com.google.inject.internal.InjectorImpl.initializeBinding (InjectorImpl.java:581)
at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run (AbstractBindingProcessor.java:176)
at com.google.inject.internal.ProcessedBindingData.initializeBindings (ProcessedBindingData.java:49)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically (InternalInjectorCreator.java:122)
at com.google.inject.internal.InternalInjectorCreator.build (InternalInjectorCreator.java:106)
at com.google.inject.Guice.createInjector (Guice.java:87)
at com.google.inject.Guice.createInjector (Guice.java:69)
at com.google.inject.Guice.createInjector (Guice.java:59)
at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector (DefaultPlexusContainer.java:481)
at org.codehaus.plexus.DefaultPlexusContainer.<init> (DefaultPlexusContainer.java:206)
at org.apache.maven.cli.MavenCli.container (MavenCli.java:635)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:281)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.IllegalStateException: Unable to load cache item
at com.google.inject.internal.cglib.core.internal.$LoadingCache.createEntry (LoadingCache.java:79)
at com.google.inject.internal.cglib.core.internal.$LoadingCache.get (LoadingCache.java:34)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData.get (AbstractClassGenerator.java:119)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create (AbstractClassGenerator.java:294)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create (FastClass.java:65)
at com.google.inject.internal.BytecodeGen.newFastClassForMember (BytecodeGen.java:258)
at com.google.inject.internal.BytecodeGen.newFastClassForMember (BytecodeGen.java:207)
at com.google.inject.internal.DefaultConstructionProxyFactory.create (DefaultConstructionProxyFactory.java:49)
at com.google.inject.internal.ProxyFactory.create (ProxyFactory.java:156)
at com.google.inject.internal.ConstructorInjectorStore.createConstructor (ConstructorInjectorStore.java:92)
at com.google.inject.internal.ConstructorInjectorStore.access$000 (ConstructorInjectorStore.java:29)
at com.google.inject.internal.ConstructorInjectorStore$1.create (ConstructorInjectorStore.java:37)
at com.google.inject.internal.ConstructorInjectorStore$1.create (ConstructorInjectorStore.java:33)
at com.google.inject.internal.FailableCache$1.load (FailableCache.java:40)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture (LocalCache.java:3540)
at com.google.common.cache.LocalCache$Segment.loadSync (LocalCache.java:2321)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad (LocalCache.java:2284)
at com.google.common.cache.LocalCache$Segment.get (LocalCache.java:2199)
at com.google.common.cache.LocalCache.get (LocalCache.java:3951)
at com.google.common.cache.LocalCache.getOrLoad (LocalCache.java:3955)
at com.google.common.cache.LocalCache$LocalLoadingCache.get (LocalCache.java:4870)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked (LocalCache.java:4876)
at com.google.inject.internal.FailableCache.get (FailableCache.java:51)
at com.google.inject.internal.ConstructorInjectorStore.get (ConstructorInjectorStore.java:48)
at com.google.inject.internal.ConstructorBindingImpl.initialize (ConstructorBindingImpl.java:155)
at com.google.inject.internal.InjectorImpl.initializeBinding (InjectorImpl.java:581)
at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run (AbstractBindingProcessor.java:176)
at com.google.inject.internal.ProcessedBindingData.initializeBindings (ProcessedBindingData.java:49)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically (InternalInjectorCreator.java:122)
at com.google.inject.internal.InternalInjectorCreator.build (InternalInjectorCreator.java:106)
at com.google.inject.Guice.createInjector (Guice.java:87)
at com.google.inject.Guice.createInjector (Guice.java:69)
at com.google.inject.Guice.createInjector (Guice.java:59)
at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector (DefaultPlexusContainer.java:481)
at org.codehaus.plexus.DefaultPlexusContainer.<init> (DefaultPlexusContainer.java:206)
at org.apache.maven.cli.MavenCli.container (MavenCli.java:635)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:281)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper
at com.google.inject.internal.cglib.core.$DuplicatesPredicate.evaluate (DuplicatesPredicate.java:104)
at com.google.inject.internal.cglib.core.$CollectionUtils.filter (CollectionUtils.java:52)
at com.google.inject.internal.cglib.reflect.$FastClassEmitter.<init> (FastClassEmitter.java:69)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass (FastClass.java:77)
at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate (DefaultGeneratorStrategy.java:25)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.generate (AbstractClassGenerator.java:332)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData$3.apply (AbstractClassGenerator.java:96)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData$3.apply (AbstractClassGenerator.java:94)
at com.google.inject.internal.cglib.core.internal.$LoadingCache$2.call (LoadingCache.java:54)
at java.util.concurrent.FutureTask.run (FutureTask.java:264)
at com.google.inject.internal.cglib.core.internal.$LoadingCache.createEntry (LoadingCache.java:61)
at com.google.inject.internal.cglib.core.internal.$LoadingCache.get (LoadingCache.java:34)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData.get (AbstractClassGenerator.java:119)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create (AbstractClassGenerator.java:294)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create (FastClass.java:65)
at com.google.inject.internal.BytecodeGen.newFastClassForMember (BytecodeGen.java:258)
at com.google.inject.internal.BytecodeGen.newFastClassForMember (BytecodeGen.java:207)
at com.google.inject.internal.DefaultConstructionProxyFactory.create (DefaultConstructionProxyFactory.java:49)
at com.google.inject.internal.ProxyFactory.create (ProxyFactory.java:156)
at com.google.inject.internal.ConstructorInjectorStore.createConstructor (ConstructorInjectorStore.java:92)
at com.google.inject.internal.ConstructorInjectorStore.access$000 (ConstructorInjectorStore.java:29)
at com.google.inject.internal.ConstructorInjectorStore$1.create (ConstructorInjectorStore.java:37)
at com.google.inject.internal.ConstructorInjectorStore$1.create (ConstructorInjectorStore.java:33)
at com.google.inject.internal.FailableCache$1.load (FailableCache.java:40)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture (LocalCache.java:3540)
at com.google.common.cache.LocalCache$Segment.loadSync (LocalCache.java:2321)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad (LocalCache.java:2284)
at com.google.common.cache.LocalCache$Segment.get (LocalCache.java:2199)
at com.google.common.cache.LocalCache.get (LocalCache.java:3951)
at com.google.common.cache.LocalCache.getOrLoad (LocalCache.java:3955)
at com.google.common.cache.LocalCache$LocalLoadingCache.get (LocalCache.java:4870)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked (LocalCache.java:4876)
at com.google.inject.internal.FailableCache.get (FailableCache.java:51)
at com.google.inject.internal.ConstructorInjectorStore.get (ConstructorInjectorStore.java:48)
at com.google.inject.internal.ConstructorBindingImpl.initialize (ConstructorBindingImpl.java:155)
at com.google.inject.internal.InjectorImpl.initializeBinding (InjectorImpl.java:581)
at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run (AbstractBindingProcessor.java:176)
at com.google.inject.internal.ProcessedBindingData.initializeBindings (ProcessedBindingData.java:49)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically (InternalInjectorCreator.java:122)
at com.google.inject.internal.InternalInjectorCreator.build (InternalInjectorCreator.java:106)
at com.google.inject.Guice.createInjector (Guice.java:87)
at com.google.inject.Guice.createInjector (Guice.java:69)
at com.google.inject.Guice.createInjector (Guice.java:59)
at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector (DefaultPlexusContainer.java:481)
at org.codehaus.plexus.DefaultPlexusContainer.<init> (DefaultPlexusContainer.java:206)
at org.apache.maven.cli.MavenCli.container (MavenCli.java:635)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:281)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)



windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

TakahitoIwasa avatar image
0 Votes"
TakahitoIwasa answered

Hi, @CHEKOORJaya-3067

I understand that you want to use Maven with Java 11 in Azure Cloud Shell.

You cannot change the default installation version of Cloud Shell.
And since you can't use root privileges in Cloud Shell, you can't install additional Java 11 with apt-get.

However, you can additionally manually download and install Java 11.

Microsoft Build of JRE 11 is available at:
https://docs.microsoft.com/en-us/java/openjdk/download

You can expand it to any location and change the environment variables PATH and JAVA_HOME. Maven will be aware of Java 11.

iwasa_takahito@Azure:~/jdk-11.0.15+10/bin$ export PATH=/home/iwasa_takahito/jdk-11.0.15+10/bin:$PATH
iwasa_takahito@Azure:~/jdk-11.0.15+10/bin$ export JAVA_HOME=/home/iwasa_takahito/jdk-11.0.15+10

iwasa_takahito@Azure:~/jdk-11.0.15+10/bin$ mvn -X
Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 11.0.15, vendor: Microsoft, runtime: /home/iwasa_takahito/jdk-11.0.15+10
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-1078-azure", arch: "amd64", family: "unix"
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[DEBUG] Created new class realm maven.api
[DEBUG] Importing foreign packages into class realm maven.api
[DEBUG]   Imported: javax.annotation.* < plexus.core
[DEBUG]   Imported: javax.annotation.security.* < plexus.core
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.