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.
Starting with your last paragraph
Ubuntu provides a nice tool to select one JDK/JRE from multiple installations. This is
update-java-alternatives
. It is closely tied to theupdate-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 theopenjdk-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)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 inupdate-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 JDKupdate-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
usesupdate-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 usingupdate-alternatives
for each tool. So, when you useupdate-java-alternatives
to select a JDK, sayopenjdk-8-jdk
for example, it makes the java tools of this JDK (such asjavac
,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 andupdate-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 useupdate-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 changinghl
tojre
andjdkhl
tojdk
in.jinfo
file. I've found an old.jinfo
file on github where those werejre
andjdk
.The fix for
.jinfo
file.So, To fix it use you need to change
hl
andjdkhl
s. If your file is.openjdk-8-jdk.jinfo
in/usr/lib/jvm/
use this commandNow to update, first list the alternatives
It will return something like this (the actual reply may be different for you)
Copy the alternative name from the first column and use it to set default. To set
jdk1.8.0_65
as default I'd useNow, check the
java
andjavac
version.My PATH is in some way influenced by the file
/etc/environment
as you can see:When I execute
which java
andwhich javac
I see something like follows:Now, I can't be sure the two are related.* but as a Java dev I'm often adding things to Path - it's how we influence CLASSPATH so that our Java classes are available. And in the Path configuration above you see this excerpt:
I don't know what that means. Nevertheless by following the targets given to me by the
which
command I come to a set of links to executables. Looking at the targets of those links I get something like:Unsure on next steps. Copy those links, back them up or remove them. A bit of trial and error and Googling are the next steps. I haven't googled the difference between
javac -version
andwhich
but I shouldHTH and thanks to BryceAtNetwork23