红联Linux门户
Linux帮助
当前位置: 红联Linux门户 > SuSE

成功在openSUSE 12.3上 安装 Oracle 发行的JDK7,贴出脚本分享

发布时间:2013-06-11 20:58:47来源:红联作者:sauntor
这两天宅在家里,专门研究了一下JDK的安装(可惜openJDK不支持JavaFX 2呀,要不就不用这么费劲了……),参照openSUSE官方指南和以前版本Sun JDK RPM的SPEC文件,自己写了一个自动安装配置脚本,特贴出以期能抛砖引玉,引来高手批评指教。[code]priority=20000
origin=oracle
javamajver=${javamajver}
javaminver=21
jdktar=./jdk-7u${javaminver}-linux-i586.tar.gz

_mandir=/usr/share/man
libdir=/usr/lib
bindir=/usr/bin
#if [ -d /usr/lib64 ]; then
# libdir=/usr/lib64
#fi
jvmdir=$libdir/jvm
sdklnk=java-${javamajver}-$origin
jredir=$jvmdir/$sdklnk/jre
jrebindir=$jredir/bin
sdkbindir=$jvmdir/$sdklnk/bin
sdkman=$jvmdir/$sdklnk/man
jrelnk=jre-${javamajver}-$origin
jvmjardir=$libdir/jvm-exports

install_jdk()
{
tar -xzf $jdktar -C $jvmdir
cd $jvmdir

chown -R root:root jdk${javamajver}_${javaminver}
ln -s -T $jvmdir/jdk${javamajver}_${javaminver} $sdklnk
ln -s -T $jvmdir/jdk${javamajver}_${javaminver}/jre $jrelnk

for man1file in $(ls $sdklnk/man/man1); do
gzip $(readlink -f $sdklnk/man/man1/$man1file)
done

mkdir $jvmjardir/$sdklnk
ln -s $jvmjardir/$sdklnk $jvmjardir/$jrelnk

cd -

cd $jvmjardir/$sdklnk

ln -s $jvmdir/$sdklnk/jre/lib/rt.jar jaas-${javamajver}_$origin.jar
ln -s jaas-${javamajver}_$origin.jar jaas-${javamajver}.jar
ln -s jaas-${javamajver}_$origin.jar jaas.jar
ln -s $jvmdir/$sdklnk/jre/lib/jce.jar jce-${javamajver}_$origin.jar
ln -s jce-${javamajver}_$origin.jar jce-${javamajver}.jar
ln -s jce-${javamajver}_$origin.jar jce.jar
ln -s $jvmdir/$sdklnk/jre/lib/rt.jar jdbc-stdext-${javamajver}_$origin.jar
ln -s jdbc-stdext-${javamajver}_$origin.jar jdbc-stdext-${javamajver}.jar
ln -s jdbc-stdext-${javamajver}_$origin.jar jdbc-stdext-3.0.jar
ln -s jdbc-stdext-${javamajver}_$origin.jar jdbc-stdext.jar
ln -s $jvmdir/$sdklnk/jre/lib/rt.jar jndi-${javamajver}_$origin.jar
ln -s jndi-${javamajver}_$origin.jar jndi-${javamajver}.jar
ln -s $jvmdir/$sdklnk/jre/lib/rt.jar jndi-cos-${javamajver}_$origin.jar
ln -s jndi-cos-${javamajver}_$origin.jar jndi-cos-${javamajver}.jar
ln -s jndi-cos-${javamajver}_$origin.jar jndi-cos.jar
ln -s jndi-${javamajver}_$origin.jar jndi.jar
ln -s $jvmdir/$sdklnk/jre/lib/rt.jar jndi-ldap-${javamajver}_$origin.jar
ln -s jndi-ldap-${javamajver}_$origin.jar jndi-ldap-${javamajver}.jar
ln -s jndi-ldap-${javamajver}_$origin.jar jndi-ldap.jar
ln -s $jvmdir/$sdklnk/jre/lib/rt.jar jndi-rmi-${javamajver}_$origin.jar
ln -s jndi-rmi-${javamajver}_$origin.jar jndi-rmi-${javamajver}.jar
ln -s jndi-rmi-${javamajver}_$origin.jar jndi-rmi.jar
ln -s $jvmdir/$sdklnk/jre/lib/jsse.jar jsse-${javamajver}_$origin.jar
ln -s jsse-${javamajver}_$origin.jar jsse-${javamajver}.jar
ln -s jsse-${javamajver}_$origin.jar jsse.jar
ln -s $jvmdir/$sdklnk/jre/lib/rt.jar sasl-${javamajver}_$origin.jar
ln -s sasl-${javamajver}_$origin.jar sasl-${javamajver}.jar
ln -s sasl-${javamajver}_$origin.jar sasl.jar
# jrokit
ln -s $jvmdir/$sdklnk/jre/lib/jfr.jar jfr-${javamajver}_$origin.jar
ln -s jfr-${javamajver}_$origin.jar jfr-${javamajver}.jar
ln -s jfr-${javamajver}_$origin.jar jfr.jar
# jfx
ln -s $jvmdir/$sdklnk/jre/lib/jfxrt.jar jfx-${javamajver}_$origin.jar
ln -s jfx-${javamajver}_$origin.jar jfx-${javamajver}.jar
ln -s jfx-${javamajver}_$origin.jar jfx.jar
ln -s jfx.jar jfxrt.jar
# plugin
ln -s $jvmdir/$sdklnk/jre/lib/plugin.jar plugin-${javamajver}_$origin.jar
ln -s plugin-${javamajver}_$origin.jar plugin-${javamajver}.jar
ln -s plugin-${javamajver}_$origin.jar plugin.jar
ln -s plugin.jar jnlp.jar
# javaws
ln -s $jvmdir/$sdklnk/jre/lib/javaws.jar javaws-${javamajver}_$origin.jar
ln -s javaws-${javamajver}_$origin.jar javaws-${javamajver}.jar
ln -s javaws-${javamajver}_$origin.jar javaws.jar
# deploy
ln -s $jvmdir/$sdklnk/jre/lib/deploy.jar deploy-${javamajver}_$origin.jar
ln -s deploy-${javamajver}_$origin.jar deploy-${javamajver}.jar
ln -s deploy-${javamajver}_$origin.jar deploy.jar

cd -

# JRE
update-alternatives --install $jvmdir/jre-$origin jre_$origin $jvmdir/$jrelnk $priority \
--slave $jvmjardir/jre-$origin jre_${origin}_exports $jvmjardir/$jrelnk
update-alternatives --install $jvmdir/jre-${javamajver} jre_${javamajver} $jvmdir/$jrelnk $priority \
--slave $jvmjardir/jre-${javamajver} jre_${javamajver}_exports $jvmjardir/$jrelnk

xargs update-alternatives <--install $bindir/java java $jrebindir/java $priority \
--slave $bindir/ControlPanel ControlPanel $jrebindir/ControlPanel \
--slave $bindir/java_vm java_vm $jrebindir/java_vm \
--slave $jvmdir/jre jre $jvmdir/$jrelnk \
--slave $libdir/jvm-exports/jre jre_exports $libdir/jvm-exports/$jrelnk \
--slave $bindir/keytool keytool $jrebindir/keytool \
--slave $bindir/orbd orbd $jrebindir/orbd \
--slave $bindir/policytool policytool $jrebindir/policytool \
--slave $bindir/rmid rmid $jrebindir/rmid \
--slave $bindir/rmiregistry rmiregistry $jrebindir/rmiregistry \
--slave $bindir/servertool servertool $jrebindir/servertool \
--slave $bindir/tnameserv tnameserv $jrebindir/tnameserv \
--slave $_mandir/man1/java.1.gz java.1.gz $sdkman/man1/java.1.gz \
--slave $_mandir/man1/keytool.1.gz keytool.1.gz $sdkman/man1/keytool.1.gz \
--slave $_mandir/man1/orbd.1.gz orbd.1.gz $sdkman/man1/orbd.1.gz \
--slave $_mandir/man1/policytool.1.gz policytool.1.gz $sdkman/man1/policytool.1.gz \
--slave $_mandir/man1/rmid.1.gz rmid.1.gz $sdkman/man1/rmid.1.gz \
--slave $_mandir/man1/rmiregistry.1.gz rmiregistry.1.gz $sdkman/man1/rmiregistry.1.gz \
--slave $_mandir/man1/servertool.1.gz servertool.1.gz $sdkman/man1/servertool.1.gz \
--slave $_mandir/man1/tnameserv.1.gz tnameserv.1.gz $sdkman/man1/tnameserv.1.gz
EOF

# JavaPlugin
update-alternatives --install \
$libdir/browser-plugins/javaplugin.so javaplugin $jvmdir/$sdklnk/jre/lib/i386/libnpjp2.so $priority \
--slave $bindir/javaws javaws $jrebindir/javaws \
--slave $_mandir/man1/javaws.1.gz javaws.1.gz $sdkman/man1/javaws.1.gz

ln -s -T $jvmdir/$sdklnk/jre/bin/jcontrol $bindir/jcontrol
ln -s -T $jvmdir/$sdklnk/jre/lib/desktop/icons/hicolor/16x16/apps/sun-jcontrol.png /usr/share/icons/hicolor/16x16/apps/sun-jcontrol.png
ln -s -T $jvmdir/$sdklnk/jre/lib/desktop/icons/hicolor/48x48/apps/sun-jcontrol.png /usr/share/icons/hicolor/48x48/apps/sun-jcontrol.png
ln -s -T $jvmdir/$sdklnk/jre/lib/desktop/icons/LowContrast/16x16/apps/sun-jcontrol.png /usr/share/icons/locolor/16x16/apps/sun-jcontrol.png
ln -s -T $jvmdir/$sdklnk/jre/lib/desktop/icons/LowContrast/48x48/apps/sun-jcontrol.png /usr/share/icons/locolor/48x48/apps/sun-jcontrol.png
ln -s -T $jvmdir/$sdklnk/jre/lib/desktop/applications/sun_java.desktop /usr/share/applications/sun_java.desktop

# JDK
update-alternatives --install $jvmdir/java-${javamajver} java_sdk_${javamajver} $jvmdir/${sdklnk} ${priority} \
--slave ${jvmjardir}/java-${javamajver} java_sdk_${javamajver}_exports ${jvmjardir}/${sdklnk}
update-alternatives --install $jvmdir/java-${origin} java_sdk_${origin} $jvmdir/${sdklnk} ${priority} \
--slave ${jvmjardir}/java-${origin} java_sdk_${origin}_exports ${jvmjardir}/${sdklnk}

xargs update-alternatives <--install $bindir/javac javac ${sdkbindir}/javac ${priority} \
--slave $jvmdir/java java_sdk $jvmdir/${sdklnk} \
--slave ${jvmjardir}/java java_sdk_exports ${jvmjardir}/${sdklnk} \
--slave $bindir/appletviewer appletviewer ${sdkbindir}/appletviewer \
--slave $bindir/extcheck extcheck ${sdkbindir}/extcheck \
--slave $bindir/idlj idlj ${sdkbindir}/idlj \
--slave $bindir/jar jar ${sdkbindir}/jar \
--slave $bindir/jarsigner jarsigner ${sdkbindir}/jarsigner \
--slave $bindir/javadoc javadoc ${sdkbindir}/javadoc \
--slave $bindir/javah javah ${sdkbindir}/javah \
--slave $bindir/javap javap ${sdkbindir}/javap \
--slave $bindir/jdb jdb ${sdkbindir}/jdb \
--slave $bindir/native2ascii native2ascii ${sdkbindir}/native2ascii \
--slave $bindir/rmic rmic ${sdkbindir}/rmic \
--slave $bindir/serialver serialver ${sdkbindir}/serialver \
--slave $bindir/jconsole jconsole ${sdkbindir}/jconsole \
--slave $bindir/pack200 pack200 ${sdkbindir}/pack200 \
--slave $bindir/unpack200 unpack200 ${sdkbindir}/unpack200 \
--slave $bindir/wsimport wsimport ${sdkbindir}/wsimport \
--slave $bindir/apt apt ${sdkbindir}/apt \
--slave $bindir/jinfo jinfo ${sdkbindir}/jinfo \
--slave $bindir/jmap jmap ${sdkbindir}/jmap \
--slave $bindir/jps jps ${sdkbindir}/jps \
--slave $bindir/jsadebugd jsadebugd ${sdkbindir}/jsadebugd \
--slave $bindir/jstack jstack ${sdkbindir}/jstack \
--slave $bindir/jstat jstat ${sdkbindir}/jstat \
--slave $bindir/jstatd jstatd ${sdkbindir}/jstatd \
--slave $bindir/jvisualvm jvisualvm ${sdkbindir}/jvisualvm \
--slave $bindir/javafxpackager javafxpackager ${sdkbindir}/javafxpackager \
--slave ${_mandir}/man1/appletviewer.1.gz appletviewer.1.gz ${sdkman}/man1/appletviewer.1.gz \
--slave ${_mandir}/man1/extcheck.1.gz extcheck.1.gz ${sdkman}/man1/extcheck.1.gz \
--slave ${_mandir}/man1/idlj.1.gz idlj.1.gz ${sdkman}/man1/idlj.1.gz \
--slave ${_mandir}/man1/jar.1.gz jar.1.gz ${sdkman}/man1/jar.1.gz \
--slave ${_mandir}/man1/jarsigner.1.gz jarsigner.1.gz ${sdkman}/man1/jarsigner.1.gz \
--slave ${_mandir}/man1/javac.1.gz javac.1.gz ${sdkman}/man1/javac.1.gz \
--slave ${_mandir}/man1/javadoc.1.gz javadoc.1.gz ${sdkman}/man1/javadoc.1.gz \
--slave ${_mandir}/man1/javah.1.gz javah.1.gz ${sdkman}/man1/javah.1.gz \
--slave ${_mandir}/man1/javap.1.gz javap.1.gz ${sdkman}/man1/javap.1.gz \
--slave ${_mandir}/man1/jdb.1.gz jdb.1.gz ${sdkman}/man1/jdb.1.gz \
--slave ${_mandir}/man1/jvisualvm.1.gz jvisualvm.1.gz ${sdkman}/man1/jvisualvm.1.gz \
--slave ${_mandir}/man1/native2ascii.1.gz native2ascii.1.gz ${sdkman}/man1/native2ascii.1.gz \
--slave ${_mandir}/man1/rmic.1.gz rmic.1.gz ${sdkman}/man1/rmic.1.gz \
--slave ${_mandir}/man1/serialver.1.gz serialver.1.gz ${sdkman}/man1/serialver.1.gz \
--slave ${_mandir}/man1/jconsole.1.gz jconsole.1.gz ${sdkman}/man1/jconsole.1.gz \
--slave ${_mandir}/man1/pack200.1.gz pack200.1.gz ${sdkman}/man1/pack200.1.gz \
--slave ${_mandir}/man1/unpack200.1.gz unpack200.1.gz ${sdkman}/man1/unpack200.1.gz \
--slave ${_mandir}/man1/apt.1.gz apt.1.gz ${sdkman}/man1/apt.1.gz \
--slave ${_mandir}/man1/jinfo.1.gz jinfo.1.gz ${sdkman}/man1/jinfo.1.gz \
--slave ${_mandir}/man1/jmap.1.gz jmap.1.gz ${sdkman}/man1/jmap.1.gz \
--slave ${_mandir}/man1/jps.1.gz jps.1.gz ${sdkman}/man1/jps.1.gz \
--slave ${_mandir}/man1/jsadebugd.1.gz jsadebugd.1.gz ${sdkman}/man1/jsadebugd.1.gz \
--slave ${_mandir}/man1/jstack.1.gz jstack.1.gz ${sdkman}/man1/jstack.1.gz \
--slave ${_mandir}/man1/jstat.1.gz jstat.1.gz ${sdkman}/man1/jstat.1.gz \
--slave ${_mandir}/man1/jstatd.1.gz jstatd.1.gz ${sdkman}/man1/jstatd.1.gz \
--slave ${_mandir}/man1/wsimport.1.gz wsimport.1.gz ${sdkman}/man1/wsimport.1.gz
EOF
}

uninstall_jdk()
{
update-alternatives --remove javac ${sdkbindir}/javac
update-alternatives --remove java_sdk_${javamajver} $jvmdir/${sdklnk}
update-alternatives --remove java_sdk_${origin} $jvmdir/${sdklnk}
update-alternatives --remove javaplugin $jvmdir/$sdklnk/jre/lib/i386/libnpjp2.so
update-alternatives --remove java $jrebindir/java
update-alternatives --remove jre_${javamajver} $jvmdir/$jrelnk
update-alternatives --remove jre_$origin $jvmdir/$jrelnk
rm $jvmdir/$jrelnk
rm $jvmdir/$sdklnk
rm -rf $jvmdir/jdk${javamajver}_${javaminver}
}

print_help()
{
echo <usage:
$(basename $scriptname) [jdkpkg] update
jdkpkg the path to jdk archive file, for example: ~/download/jdk-7u21-linux-i586.tar.gz
if omitted, it is jdk-7u21-linux-i586.tar.gz in \$PWD
update the patch version of jdk, it's the number after "7u" of the jdk file name, for the above file, it's "21"
EOF
}

#############################
scriptname=$0
cmdname=$1
case $# in
3)
jdktar=$2
javaminver=$3
jdktar=./jdk-7u${javaminver}-linux-i586.tar.gz
;;
2)
javaminver=$2
jdktar=./jdk-7u${javaminver}-linux-i586.tar.gz
;;
1)
# nop
;;
*)
print_help
exit 1
;;
esac

case $cmdname in
install)
install_jdk
;;
remove)
uninstall_jdk
;;
esac
[/code]
文章评论

共有 7 条评论

  1. xingzai2013 于 2015-03-20 09:43:16发表:

    学习学习

  2. Luopen 于 2014-12-02 21:22:34发表:

    好资料

  3. Nick_77 于 2014-04-26 16:25:19发表:

    好贴,顶

  4. 纠结de人类 于 2013-12-06 18:42:33发表:

    嗯,挺好

  5. leumouse 于 2013-07-30 10:05:08发表:

    学习学习

  6. Growth兆 于 2013-06-12 09:02:42发表:

    感谢sauntor的分享,本贴加入到最新openSUSE技术贴子中

  7. tworkprod 于 2013-06-12 08:42:53发表:

    强呀