Tuesday, May 14, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 1184  / 1 Year ago, fri, april 21, 2023, 5:40:10

I'm running Pangolin (12.04 LTS) and want to sort out some Java stuff where my JVM is pointing at a different place to my Compiler.



To demonstrate, my JVM is as follows:



pcrow@pcrow-HP-notebook:~/Documents$ java -version
java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1ubuntu0.12.04.4)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)


Whereas my Compiler points here:



pcrow@pcrow-HP-notebook:~/Documents$ javac -version
javac 1.7.0_51


I have configured the latter through adding an entry to my ~/.profile file. The thing is that I'm not sure what sets the former and I want them to be consistent. In '/etc/environment' I have the following entry:



PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"


And when I run printenv | grep "java"



PATH=/usr/share/maven/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-7-openjdk-amd64/bin
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64




Can you tell me where IcedTea6 is most likely set up on Ubuntu? I'd like to override it if I can and make sure my JVM and Compiler are both using the same version.


More From » java

 Answers
0

Starting with your last paragraph



Can you tell me where IcedTea6 is most likely set up on Ubuntu? I'd like to override it if I can and make sure my JVM and Compiler are both using the same version.



Ubuntu provides a nice tool to select one JDK/JRE from multiple installations. This is update-java-alternatives. It is closely tied to the update-alternatives tool.


Each JDK/JRE includes a set of java tools like javac, java, javaws, jinfo, javah etc. An installation may come with a hidden .jinfo file where these java components are listed. In my system, when I install the openjdk-8-jdk package, a file /usr/lib/jvm/.java-1.8.0-openjdk-amd64.jinfo is created. The content of that file is (skipped some lines)


name=java-8-openjdk-amd64
alias=java-1.8.0-openjdk-amd64
priority=1081
section=main

hl rmid /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/rmid
hl java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
hl keytool /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/keytool
hl jjs /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/jjs
hl pack200 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/pack200
hl rmiregistry /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/rmiregistry
.
.
. (skipped lines)
.
.
jdkhl jdb /usr/lib/jvm/java-8-openjdk-amd64/bin/jdb
jdkhl serialver /usr/lib/jvm/java-8-openjdk-amd64/bin/serialver
jdkhl wsgen /usr/lib/jvm/java-8-openjdk-amd64/bin/wsgen
jdkhl jcmd /usr/lib/jvm/java-8-openjdk-amd64/bin/jcmd
jdk appletviewer /usr/lib/jvm/java-8-openjdk-amd64/bin/appletviewer
jdk jconsole /usr/lib/jvm/java-8-openjdk-amd64/bin/jconsole
plugin mozilla-javaplugin.so /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so

update-java-alternatives uses this file to create alternatives links in /etc/alternatives directory. The purpose of this directory is to provide a mechanism by which you can select a default program from a set of similar tools. This is great for multiple versions of JDK (see more in update-alternatives)


Brief discussion of update-alternatives


To demonstrate the process briefly. When a program is first installed it registers its alternatives for a master name (like javac) in alternatives database (This is contained in /var/lib/dpkg/alternatives directory). During the installation process, update-alternatives creates a master link in /usr/bin/javac pointing to /etc/alternatives/javac, which is also a symlink pointing to the actual file from the JDK.


Now, When you install another JDK, this too will have a javac program. So, while installing the second JDK update-alternatives automatically updates the /etc/alternatives/javac symlink to point to the one with highest priority . It also updates the alternatives database, so that you can manually select a default by calling it.


Back to the update-java-alternatives


update-java-alternatives uses update-alternatives to provide a whole set defaults from a single JDK/JRE installation. The idea is you will select a JDK/JRE installation and all tools from that JRE/JDK will be used as default for providing multiple java tools, saving you from using update-alternatives for each tool. So, when you use update-java-alternatives to select a JDK, say openjdk-8-jdk for example, it makes the java tools of this JDK (such as javac, java, javaws etc) as default. Provided that the JDK is installed correctly and it lists its tools in .jinfo file.


TL;DR


So, to answer your query in short, IcedTea6 Plugin is configured in the .jinfo file and update-java-alternatives uses that file to update the links to point to it. So, you need to create a file for your JDK listing the plugin and all java tools and use update-java-alternatives.


If you installed JDK/JRE manually, check this question to get help making it recognized by the update-java-alternatives tool.





But we still have problems...


It seems this update-java-alternatives is not updating JDK components anymore lately. It's only updating JRE's tools. There are lots of complaints saying using this tool doesn't update all java components. After experiencing the same problem and spending almost 5 hours on it, I think I've found a fix. The solution is just changing hl to jre and jdkhl to jdk in .jinfo file. I've found an old .jinfo file on github where those were jre and jdk.


The fix for .jinfo file.


So, To fix it use you need to change hl and jdkhls. If your file is .openjdk-8-jdk.jinfo in /usr/lib/jvm/ use this command


sudo sed -i 's/^hl/jre/p' /usr/lib/jvm/.openjdk-8-jdk.jinfo
sudo sed -i 's/^jdkhl/jdk/p' /usr/lib/jvm/.openjdk-8-jdk.jinfo

Now to update, first list the alternatives


sudo update-java-alternatives -l

It will return something like this (the actual reply may be different for you)


java-1.8.0-openjdk-amd64       1081       /usr/lib/jvm/java-1.8.0-openjdk-amd64
jdk1.8.0_65 1081 /usr/lib/jvm/jdk1.8.0_65

Copy the alternative name from the first column and use it to set default. To set jdk1.8.0_65 as default I'd use


sudo update-java-alternatives -s jdk1.8.0_65 -v

Now, check the java and javac version.


[#27024] Saturday, April 22, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
unsmmoth

Total Points: 72
Total Questions: 113
Total Answers: 95

Location: Thailand
Member since Tue, Oct 6, 2020
4 Years ago
;