Skip to content

Instantly share code, notes, and snippets.

@olagache
Last active October 21, 2021 14:12
Show Gist options
  • Save olagache/a2eff8b2bbc95e03280b to your computer and use it in GitHub Desktop.
Save olagache/a2eff8b2bbc95e03280b to your computer and use it in GitHub Desktop.
Generate ".jdk1.8.jinfo" and "alternatives.sh" files to install java 8 using ubuntu alternatives.
alias=jdk1.8
section=non-free
jre servertool /usr/lib/jvm/jdk1.8/jre/bin/servertool
jre keytool /usr/lib/jvm/jdk1.8/jre/bin/keytool
jre java /usr/lib/jvm/jdk1.8/jre/bin/java
jre jcontrol /usr/lib/jvm/jdk1.8/jre/bin/jcontrol
jre rmid /usr/lib/jvm/jdk1.8/jre/bin/rmid
jre ControlPanel /usr/lib/jvm/jdk1.8/jre/bin/ControlPanel
jre rmiregistry /usr/lib/jvm/jdk1.8/jre/bin/rmiregistry
jre orbd /usr/lib/jvm/jdk1.8/jre/bin/orbd
jre jjs /usr/lib/jvm/jdk1.8/jre/bin/jjs
jre pack200 /usr/lib/jvm/jdk1.8/jre/bin/pack200
jre tnameserv /usr/lib/jvm/jdk1.8/jre/bin/tnameserv
jre unpack200 /usr/lib/jvm/jdk1.8/jre/bin/unpack200
jre policytool /usr/lib/jvm/jdk1.8/jre/bin/policytool
jre javaws /usr/lib/jvm/jdk1.8/jre/bin/javaws
jdk rmic /usr/lib/jvm/jdk1.8/bin/rmic
jdk jvisualvm /usr/lib/jvm/jdk1.8//bin/jvisualvm
jdk xjc /usr/lib/jvm/jdk1.8/bin/xjc
jdk jinfo /usr/lib/jvm/jdk1.8/bin/jinfo
jdk schemagen /usr/lib/jvm/jdk1.8/bin/schemagen
jdk jdb /usr/lib/jvm/jdk1.8/bin/jdb
jdk java-rmi.cgi /usr/lib/jvm/jdk1.8/bin/java-rmi.cgi
jdk wsimport /usr/lib/jvm/jdk1.8/bin/wsimport
jdk jarsigner /usr/lib/jvm/jdk1.8/bin/jarsigner
jdk jmap /usr/lib/jvm/jdk1.8/bin/jmap
jdk serialver /usr/lib/jvm/jdk1.8/bin/serialver
jdk jcmd /usr/lib/jvm/jdk1.8/bin/jcmd
jdk native2ascii /usr/lib/jvm/jdk1.8/bin/native2ascii
jdk jstatd /usr/lib/jvm/jdk1.8/bin/jstatd
jdk javac /usr/lib/jvm/jdk1.8/bin/javac
jdk jstack /usr/lib/jvm/jdk1.8/bin/jstack
jdk wsgen /usr/lib/jvm/jdk1.8/bin/wsgen
jdk jmc.ini /usr/lib/jvm/jdk1.8/bin/jmc.ini
jdk idlj /usr/lib/jvm/jdk1.8/bin/idlj
jdk javah /usr/lib/jvm/jdk1.8/bin/javah
jdk jmc /usr/lib/jvm/jdk1.8/bin/jmc
jdk javafxpackager /usr/lib/jvm/jdk1.8/bin/javafxpackager
jdk javapackager /usr/lib/jvm/jdk1.8/bin/javapackager
jdk jsadebugd /usr/lib/jvm/jdk1.8/bin/jsadebugd
jdk jps /usr/lib/jvm/jdk1.8/bin/jps
jdk jrunscript /usr/lib/jvm/jdk1.8/bin/jrunscript
jdk jhat /usr/lib/jvm/jdk1.8/bin/jhat
jdk javap /usr/lib/jvm/jdk1.8/bin/javap
jdk jdeps /usr/lib/jvm/jdk1.8/bin/jdeps
jdk jstat /usr/lib/jvm/jdk1.8/bin/jstat
jdk appletviewer /usr/lib/jvm/jdk1.8/bin/appletviewer
jdk extcheck /usr/lib/jvm/jdk1.8/bin/extcheck
jdk javadoc /usr/lib/jvm/jdk1.8/bin/javadoc
jdk jar /usr/lib/jvm/jdk1.8/bin/jar
jdk jconsole /usr/lib/jvm/jdk1.8/bin/jconsole
update-alternatives --install /usr/bin/servertool servertool /usr/lib/jvm/jdk1.8/jre/bin/servertool 1820
update-alternatives --install /usr/bin/keytool keytool /usr/lib/jvm/jdk1.8/jre/bin/keytool 1820
update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8/jre/bin/java 1820
update-alternatives --install /usr/bin/jcontrol jcontrol /usr/lib/jvm/jdk1.8/jre/bin/jcontrol 1820
update-alternatives --install /usr/bin/rmid rmid /usr/lib/jvm/jdk1.8/jre/bin/rmid 1820
update-alternatives --install /usr/bin/ControlPanel ControlPanel /usr/lib/jvm/jdk1.8/jre/bin/ControlPanel 1820
update-alternatives --install /usr/bin/rmiregistry rmiregistry /usr/lib/jvm/jdk1.8/jre/bin/rmiregistry 1820
update-alternatives --install /usr/bin/orbd orbd /usr/lib/jvm/jdk1.8/jre/bin/orbd 1820
update-alternatives --install /usr/bin/jjs jjs /usr/lib/jvm/jdk1.8/jre/bin/jjs 1820
update-alternatives --install /usr/bin/pack200 pack200 /usr/lib/jvm/jdk1.8/jre/bin/pack200 1820
update-alternatives --install /usr/bin/tnameserv tnameserv /usr/lib/jvm/jdk1.8/jre/bin/tnameserv 1820
update-alternatives --install /usr/bin/unpack200 unpack200 /usr/lib/jvm/jdk1.8/jre/bin/unpack200 1820
update-alternatives --install /usr/bin/policytool policytool /usr/lib/jvm/jdk1.8/jre/bin/policytool 1820
update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.8/jre/bin/javaws 1820
update-alternatives --install /usr/bin/rmic rmic /usr/lib/jvm/jdk1.8/bin/rmic 1820
update-alternatives --install /usr/bin/jvisualvm jvisualvm /usr/lib/jvm/jdk1.8/bin/jvisualvm 1820
update-alternatives --install /usr/bin/xjc xjc /usr/lib/jvm/jdk1.8/bin/xjc 1820
update-alternatives --install /usr/bin/jinfo jinfo /usr/lib/jvm/jdk1.8/bin/jinfo 1820
update-alternatives --install /usr/bin/schemagen schemagen /usr/lib/jvm/jdk1.8/bin/schemagen 1820
update-alternatives --install /usr/bin/jdb jdb /usr/lib/jvm/jdk1.8/bin/jdb 1820
update-alternatives --install /usr/bin/java-rmi.cgi java-rmi.cgi /usr/lib/jvm/jdk1.8/bin/java-rmi.cgi 1820
update-alternatives --install /usr/bin/wsimport wsimport /usr/lib/jvm/jdk1.8/bin/wsimport 1820
update-alternatives --install /usr/bin/jarsigner jarsigner /usr/lib/jvm/jdk1.8/bin/jarsigner 1820
update-alternatives --install /usr/bin/jmap jmap /usr/lib/jvm/jdk1.8/bin/jmap 1820
update-alternatives --install /usr/bin/serialver serialver /usr/lib/jvm/jdk1.8/bin/serialver 1820
update-alternatives --install /usr/bin/jcmd jcmd /usr/lib/jvm/jdk1.8/bin/jcmd 1820
update-alternatives --install /usr/bin/native2ascii native2ascii /usr/lib/jvm/jdk1.8/bin/native2ascii 1820
update-alternatives --install /usr/bin/jstatd jstatd /usr/lib/jvm/jdk1.8/bin/jstatd 1820
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8/bin/javac 1820
update-alternatives --install /usr/bin/jstack jstack /usr/lib/jvm/jdk1.8/bin/jstack 1820
update-alternatives --install /usr/bin/wsgen wsgen /usr/lib/jvm/jdk1.8/bin/wsgen 1820
update-alternatives --install /usr/bin/jmc.ini jmc.ini /usr/lib/jvm/jdk1.8/bin/jmc.ini 1820
update-alternatives --install /usr/bin/idlj idlj /usr/lib/jvm/jdk1.8/bin/idlj 1820
update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.8/bin/javah 1820
update-alternatives --install /usr/bin/jmc jmc /usr/lib/jvm/jdk1.8/bin/jmc 1820
update-alternatives --install /usr/bin/javafxpackager javafxpackager /usr/lib/jvm/jdk1.8/bin/javafxpackager 1820
update-alternatives --install /usr/bin/javapackager javapackager /usr/lib/jvm/jdk1.8/bin/javapackager 1820
update-alternatives --install /usr/bin/jsadebugd jsadebugd /usr/lib/jvm/jdk1.8/bin/jsadebugd 1820
update-alternatives --install /usr/bin/jps jps /usr/lib/jvm/jdk1.8/bin/jps 1820
update-alternatives --install /usr/bin/jrunscript jrunscript /usr/lib/jvm/jdk1.8/bin/jrunscript 1820
update-alternatives --install /usr/bin/jhat jhat /usr/lib/jvm/jdk1.8/bin/jhat 1820
update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.8/bin/javap 1820
update-alternatives --install /usr/bin/jdeps jdeps /usr/lib/jvm/jdk1.8/bin/jdeps 1820
update-alternatives --install /usr/bin/jstat jstat /usr/lib/jvm/jdk1.8/bin/jstat 1820
update-alternatives --install /usr/bin/appletviewer appletviewer /usr/lib/jvm/jdk1.8/bin/appletviewer 1820
update-alternatives --install /usr/bin/extcheck extcheck /usr/lib/jvm/jdk1.8/bin/extcheck 1820
update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk1.8/bin/javadoc 1820
update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.8/bin/jar 1820
update-alternatives --install /usr/bin/jconsole jconsole /usr/lib/jvm/jdk1.8/bin/jconsole 1820
update-alternatives --install /usr/lib/xulrunner-addons/plugins/libjavaplugin.so xulrunner-1.9-javaplugin.so /usr/lib/jvm/jdk1.8/jre/lib/amd64/libnpjp2.so 1820
update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /usr/lib/jvm/jdk1.8/jre/lib/amd64/libnpjp2.so 1820
/* ============================ */
/* Update this properties first */
/* ============================ */
JDK_HOME = '/usr/lib/jvm/java-8-oracle-amd64'
JDK_LINK = '/usr/lib/jvm/jdk1.8'
PRIORITY = 1820
/* ============================ */
def parentDirectory = new File(JDK_HOME).parent
def jdkName = new File(JDK_HOME).name
def linkName = new File(JDK_LINK).name
private List<String> getBinaries(String path) {
def binaries = new File(path)
if(!binaries.exists() || !binaries.directory) {
return null
}
def binaryFiles = []
binaries.eachFile() { file ->
if(file.isFile() && file.canExecute()) {
binaryFiles << file.name
}
}
binaryFiles
}
def getJreBinaries() {
return getBinaries("${JDK_HOME}/jre/bin")
}
def getJdkBinaries() {
return getBinaries("${JDK_HOME}/bin")
}
if(! new File(JDK_HOME).exists()) {
println "JDK_HOME not found in ${JDK_HOME}"
return
}
if(!new File(JDK_LINK).exists()) {
println "Create symbolic link before : ${JDK_LINK}"
return
}
def jinfoFile = new File(".${linkName}.jinfo")
def alternativesFile = new File("alternatives.sh")
def ln = System.getProperty('line.separator')
if(jinfoFile.exists()) {
jinfoFile.delete()
}
if(alternativesFile.exists()) {
alternativesFile.delete()
}
jinfoFile << "alias=${linkName}$ln"
jinfoFile << "section=non-free$ln"
jreBinaries.each() {
jinfoFile << "jre ${it} ${JDK_LINK}/jre/bin/${it}$ln"
alternativesFile << "update-alternatives --install /usr/bin/${it} ${it} ${JDK_LINK}/jre/bin/${it} ${PRIORITY}$ln"
}
def subJdk = jdkBinaries.findAll { !jreBinaries.contains(it)}
subJdk.each() {
jinfoFile << "jdk ${it} ${JDK_LINK}/bin/${it}$ln"
alternativesFile << "update-alternatives --install /usr/bin/${it} ${it} ${JDK_LINK}/bin/${it} ${PRIORITY}$ln"
}
alternativesFile << "update-alternatives --install /usr/lib/xulrunner-addons/plugins/libjavaplugin.so xulrunner-1.9-javaplugin.so ${JDK_LINK}/jre/lib/amd64/libnpjp2.so ${PRIORITY}$ln"
alternativesFile << "update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so ${JDK_LINK}/jre/lib/amd64/libnpjp2.so ${PRIORITY}$ln"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment