I had openjdk 11.0.2 installed. I upgraded the java version by running
sudo apt update
sudo apt install openjdk-11-jdk
If I run sudo apt install openjdk-11-jdk again, it shows a message saying that "openjdk-11-jdk is already the newest version (11.0.11+9-0ubuntu2~20.04)"
However, when I do java -version it displays the older version 11.0.2 not 11.0.11
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
The JAVA_HOME still shows "/opt/java/jdk-11.0.2", so I guess this might be the problem that the java -version is still showing the older version?
When I do whereis java it shows
java: /usr/bin/java /usr/share/java /opt/java/jdk-11.0.2/bin/java /mnt/c/Program Files/Common Files/Oracle/Java/javapath_target_917640/java.exe /usr/share/man/man1/java.1.gz
Not sure where the newest version was installed so that I can make the JAVA_HOME point to that one
openjdk-11-jdk-headless_11.0.11+9-0ubuntu2~20.04_amd64.deb and openjdk-11-jre-headless_11.0.11+9-0ubuntu2~20.04_amd64.deb package shows (by extracting with 7-zip) that OpenJDK 11 will be installed at /usr/lib/jvm/java-11-openjdk-amd64.
This will give you enough information about appending environment variables such as PATH and JAVA_PATH.
And, there may be a path called default-jvm or so, you may use that path accordingly.
Related
I want to install open office in my centos linux and as part of the requirement is jdk 11.0.2 version.
I installed new version of java JDK 11.0.2 however when I use the command java -version it is still showing that it is using old version of java.
java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
i created the file /etc/profile.d/jdk11.sh and ran the command below
"source /etc/profile.d/jdk11.sh"
the file contains
export JAVA_HOME=/usr/local/jdk-11.0.2
export PATH=$PATH:$JAVA_HOME/bin
Given that you are using centOS:
try the following command:
sudo update-alternatives --config java
It should show you the list of available Java versions in your system. You can switch using the numbers shown in the result of the command.
tl,dr;
Doing export JAVA_HOME=$(/usr/libexec/java_home -v 14) once JAVA_HOME was already set won't change active java
Steps
set JAVA_HOME first (for example with export JAVA_HOME=$(/usr/libexec/java_home -v 11)):
$ echo ${JAVA_HOME}
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)
Try to set it to different version (for example export JAVA_HOME=$(/usr/libexec/java_home -v 14)) - it still uses previously set java (even though JAVA_HOME was updated):
$ echo ${JAVA_HOME}
/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home
$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)
I'm not sure why it's not working now - it was working just fine a while back (I'd say 2-3 months ago)
There is a seemingly similar topic (Can't set JAVA_HOME on Catalina) but it boils down to different shell. In my case I'm using same shell - bash from brew:
$ bash -version
GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Seems update JAVA_HOME is not getting reflected in PATH variable.
So, please update PATH variable also and keep the updated JAVA_HOME as the first element in the export PATH command
OK, I finally managed to solve the issue. As other have pointed out, everything has to do with PATH variable. And I indeed had JAVA_HOME/bin in there… which causes the problem. Today during an update I notice that openjdk brew formula had this comment:
keg_only "it shadows the macOS `java` wrapper"
And things immediately "clicked". After searching a bit I found Why isn't java wrapper not picking up the right version specified in JAVA_HOME on macOS? which confirmed the issue. By including JAVA_HOME in the PATH in my .profile file I was breaking native macOS functionality of it's java wrapper, which selects active java version based on currently set JAVA_HOME.
This is my example session (from opening the shell and having export JAVA_HOME=$(/usr/libexec/java_home -v 11) in the .profile file) -- I have default from the profile, then I set explicitly JAVA_HOME and it switches java version on the fly:
$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)
$ export JAVA_HOME=$(/usr/libexec/java_home -v 14)
$ java -version
openjdk version "14.0.2" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.2+12)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.2+12, mixed mode, sharing)
Trying to run Eclipse Neon I'm getting this error:
To open “Eclipse” you need to install the legacy Java SE 6 runtime.
Instead of the legacy JRE, I have already installed JRE 1.8 from Oracle:
➜ /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
However, I can also see it is not available in the path:
➜ java -v
No Java runtime present, requesting install.
➜ /usr/libexec/java_home -v 1.8
Unable to find any JVMs matching version "1.8".
No Java runtime present, try --request to install.
➜ ls /Library/Java/JavaVirtualMachines
On macOS you must install the full JDK to get complete Java support. The JRE is not sufficient as it only installs the browser plugins.
The current download for the JDK is here
I was running a geoscript-groovy tutorial code:
groovy:000> import geoscript.layer.GeoTIFF
groovy:000> format = new GeoTIFF()
groovy:000> raster = format.read(new File("raster.tif"))
, and got the follow errors:
ERROR java.lang.NoClassDefFoundError:
javax/media/jai/ImageLayout
I have limited knowledge about JAI. I don't know whether this is a general JDK configuration issue or an issue with groovy etc.
My questions are:
What's the cause of this error associated with javax.media.jai.ImageLayout and how to fix it?
How do I verify if javax.media.jai.ImageLayout is really installed.
Thanks
P.S. The software environment is Ubuntu 12.04 with:
$java -version
java version "1.6.0_32"
OpenJDK Runtime Environment (IcedTea6 1.13.4) (6b32-1.13.4-4ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
$groovy -v
Groovy Version: 1.8.6 JVM: 1.6.0_32 Vendor: Sun Microsystems Inc. OS: Linux
-- UPDATE --
I changed JDK to oracle
$ java -version
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)
and still I am getting the following error:
ERROR java.lang.NoClassDefFoundError:
javax/media/jai/ImageLayout
at org.geotools.gce.geotiff.GeoTiffFormat.getReader (GeoTiffFormat.java:287)
at org.geotools.gce.geotiff.GeoTiffFormat$getReader.call (Unknown Source)
Also, the commands I used to install Oracle JDK are:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
I also did
sudo apt-get install libjai-core-java libjai-imageio-core-java
and I am still getting the same error.
To use javax.media.jai.ImageLayout you need an Oracle JDK. It's not present in OpenJDK. I don't know the library you're using so I can't tell you if there is any option to e.g. inject different strategy for image manipulation. Switch to Oracle JDK and test if it works for you that way.
I am trying to get jmxtrans to work yet I get the below on ubuntu 12.04 and using openjdk 7.
/usr/share/jmxtrans# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
/usr/share/jmxtrans# ./jmxtrans.sh start /var/lib/jmxtrans/kafka.json
Cannot execute /usr/lib/jvm/default-java/bin/jps -l!
What does the above mean?
It seems that the jps file can't be found in the /usr/lib/jvm/default-java/bin directory. It is available in the '-devel' packages if you want to install those (yum install java-1.7.0-openjdk-devel, apt-get install openjdk-7-jre-devel). It could also be that your JAVA_HOME is not pointing to the correct place if you have multiple java versions installed.
You should not need it however, regular ps works fine. You can add a variable to your configuration that says export USE_JPS=false. The configuration can be found in /etc/default/jmxtrans.
Check out these issues for more information:
https://github.com/jmxtrans/jmxtrans/issues/89
https://github.com/jmxtrans/jmxtrans/pull/109