Mint 12 (/Ubuntu): Set up Java alternatives
Saturday, February 18th, 2012 | Java, Linux, Tech-savvy
Your modern Linux distro will provide you with a more or less decent Java setup by default. Mint 12 comes with a Sun JDK 1.6.0.26 pre-installed. To switch between installed versions of your Java runtime use the
update-java-alternatives --list |
command to list installed alternatives and
update-java-alternatives --set alternative |
to switch them. If you still want to have different versions of the JDK you can always download them manually, untar and use them directly. So far so good.
I wanted to be able to switch my downloaded JDKs as easy as the pre-installed ones, so I was looking for a way to add my JDKs to my system’s repository. So here is how it’s done (it’s basically a copy of a nice post I found, I just wanted to spread the knowledge) – it’s a bit painful but made me feel quite good when I was done
Java alternatives can be found in /usr/lib/jvm. Each installation has its own folder and a (hidden) .jinfo file. It’s not enough to simply symlink your JDK here, you have to provide a .jinfo file.
nick@silentbox /usr/lib/jvm $ ls -a . .. java-6-sun java-6-sun-1.6.0.26 .java-6-sun.jinfo |
What you need to provide in order to have a new alternative is a JDK (obviously) and a corresponding .jinfo file. Just copy one of the existing .jinfo files and change it according to your needs. In case you have no such file, here is a sample content:
name=java-6-sun-1.6.0.26 alias=java-6-sun priority=63 jre ControlPanel /usr/lib/jvm/java-6-sun/jre/bin/ControlPanel jre java /usr/lib/jvm/java-6-sun/jre/bin/java jre java_vm /usr/lib/jvm/java-6-sun/jre/bin/java_vm jre javaws /usr/lib/jvm/java-6-sun/jre/bin/javaws jre jcontrol /usr/lib/jvm/java-6-sun/jre/bin/jcontrol jre keytool /usr/lib/jvm/java-6-sun/jre/bin/keytool jre pack200 /usr/lib/jvm/java-6-sun/jre/bin/pack200 jre policytool /usr/lib/jvm/java-6-sun/jre/bin/policytool jre rmid /usr/lib/jvm/java-6-sun/jre/bin/rmid jre rmiregistry /usr/lib/jvm/java-6-sun/jre/bin/rmiregistry jre unpack200 /usr/lib/jvm/java-6-sun/jre/bin/unpack200 jre orbd /usr/lib/jvm/java-6-sun/jre/bin/orbd jre servertool /usr/lib/jvm/java-6-sun/jre/bin/servertool jre tnameserv /usr/lib/jvm/java-6-sun/jre/bin/tnameserv jre jexec /usr/lib/jvm/java-6-sun/jre/lib/jexec jdk appletviewer /usr/lib/jvm/java-6-sun/bin/appletviewer jdk apt /usr/lib/jvm/java-6-sun/bin/apt jdk extcheck /usr/lib/jvm/java-6-sun/bin/extcheck jdk HtmlConverter /usr/lib/jvm/java-6-sun/bin/HtmlConverter jdk idlj /usr/lib/jvm/java-6-sun/bin/idlj jdk jar /usr/lib/jvm/java-6-sun/bin/jar jdk jarsigner /usr/lib/jvm/java-6-sun/bin/jarsigner jdk javac /usr/lib/jvm/java-6-sun/bin/javac jdk javadoc /usr/lib/jvm/java-6-sun/bin/javadoc jdk javah /usr/lib/jvm/java-6-sun/bin/javah jdk javap /usr/lib/jvm/java-6-sun/bin/javap jdk jconsole /usr/lib/jvm/java-6-sun/bin/jconsole jdk jdb /usr/lib/jvm/java-6-sun/bin/jdb jdk jhat /usr/lib/jvm/java-6-sun/bin/jhat jdk jinfo /usr/lib/jvm/java-6-sun/bin/jinfo jdk jmap /usr/lib/jvm/java-6-sun/bin/jmap jdk jps /usr/lib/jvm/java-6-sun/bin/jps jdk jrunscript /usr/lib/jvm/java-6-sun/bin/jrunscript jdk jsadebugd /usr/lib/jvm/java-6-sun/bin/jsadebugd jdk jstack /usr/lib/jvm/java-6-sun/bin/jstack jdk jstat /usr/lib/jvm/java-6-sun/bin/jstat jdk jstatd /usr/lib/jvm/java-6-sun/bin/jstatd jdk native2ascii /usr/lib/jvm/java-6-sun/bin/native2ascii jdk rmic /usr/lib/jvm/java-6-sun/bin/rmic jdk schemagen /usr/lib/jvm/java-6-sun/bin/schemagen jdk serialver /usr/lib/jvm/java-6-sun/bin/serialver jdk wsgen /usr/lib/jvm/java-6-sun/bin/wsgen jdk wsimport /usr/lib/jvm/java-6-sun/bin/wsimport jdk xjc /usr/lib/jvm/java-6-sun/bin/xjc plugin xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so plugin firefox-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so plugin iceape-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so plugin iceweasel-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so plugin mozilla-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so plugin midbrowser-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so plugin xulrunner-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so
Change the name and alias, ignore the prio and change all directories accordingly.
I really thought I was done when I edited the .jinfo file, yet update-java-alternatives did not work yet. It’s a pain, but you have to register the stuff you just edited before you can use it. Let’s say the file we need to register is .jdk1.6.31.jinfo an the corresponding JDK is located in /opt/jdk1.6.31/
nick@silentbox /usr/lib/jvm $ cat .jdk1.6.31.jinfo | grep -E '^(jre|jdk)' | awk '{print "/usr/bin/" $2 " " $2 " " $3 " 30 \n"}' | xargs -t -n4 sudo update-alternatives --verbose --install nick@silentbox /usr/lib/jvm $ sudo update-alternatives --verbose --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /opt/jdk1.6.31/jre/lib/amd64/libnpjp2.so 30 nick@silentbox /usr/lib/jvm $ sudo update-alternatives --verbose --install /usr/lib/xulrunner-addons/plugins/libjavaplugin.so xulrunner-1.9-javaplugin.so /opt/jdk1.6.31/jre/lib/amd64/libnpjp2.so 30 |
After that update-java-alternatives --list should list your just installed alternative and you should be able to switch it natively like any other JDK the system provided out of the box.
Thanks again maciek for teaching me this in the first place
2 Comments to Mint 12 (/Ubuntu): Set up Java alternatives
Thanks, that has been very helpful.
2. April 2013
Need to update grep to include ‘hl’ for oracles 1.7.0.
grep -E ‘^(hl|jre|jdk)’
Leave a comment
Search
Categories
- (X)HTML/CSS (5)
- Activities (29)
- Gadgets (35)
- Insights (2)
- Java (22)
- Certification (1)
- IDE (10)
- JSP (1)
- Language (16)
- Quirks (9)
- Vocabulary (10)
- Linux (16)
- Misc (58)
- Photography (16)
- Reviews (69)
- Tech-savvy (81)
Tag Cloud
Archives
- May 2013 (3)
- April 2013 (1)
- March 2013 (1)
- February 2013 (1)
- January 2013 (1)
- December 2012 (3)
- November 2012 (1)
- October 2012 (3)
- September 2012 (3)
- July 2012 (1)
- May 2012 (1)
- April 2012 (1)
- February 2012 (7)
- January 2012 (1)
- December 2011 (2)
- November 2011 (4)
- October 2011 (5)
- September 2011 (3)
- August 2011 (3)
- July 2011 (2)
- June 2011 (4)
- May 2011 (1)
- April 2011 (2)
- March 2011 (2)
- February 2011 (2)
- January 2011 (6)
- December 2010 (2)
- November 2010 (5)
- October 2010 (7)
- September 2010 (13)
- August 2010 (6)
- July 2010 (4)
- June 2010 (3)
- May 2010 (3)
- April 2010 (2)
- March 2010 (2)
- February 2010 (1)
- January 2010 (1)
- December 2009 (1)
- November 2009 (2)
- October 2009 (5)
- September 2009 (1)
- August 2009 (3)
- July 2009 (5)
- June 2009 (5)
- May 2009 (6)
- April 2009 (3)
- March 2009 (3)
- February 2009 (2)
- January 2009 (1)
- December 2008 (9)
- November 2008 (15)
- October 2008 (15)
- September 2008 (13)
22. February 2012