[HOWTO] Install Sun/Oracle Java JDK 7 in Fedora 15

Sun/Oracle Java JDK 7 may be required to run some applications that are not compatible with OpenJDK which can be installed using package manager in Fedora 15. Here is how to do it. Open the terminal and use the following commands:

For 64-bit

wget "http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.rpm"
su -c 'rpm -i jdk-7-linux-x64.rpm'

For 32-bit

wget "http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.rpm"
su -c 'rpm -i jdk-7-linux-i586.rpm'

If you already have OpenJDK/OpenJRE installed, you will need to configure your system so that the applications use the Sun/Oracle Java version instead of OpenJDK/OpenJRE. Here is how to do it:

su -c 'alternatives --install /usr/bin/java java /usr/java/jdk1.7.0/jre/bin/java 20000'
su -c 'alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.7.0/jre/bin/javaws 20000'
su -c 'alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0/bin/javac 20000'
su -c 'alternatives --install /usr/bin/jar jar /usr/java/jdk1.7.0/bin/jar 20000'

For 64-bit:

su -c 'alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jdk1.7.0/jre/lib/amd64/libnpjp2.so 20000'

For 32-bit:

su -c 'alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/jdk1.7.0/jre/lib/i386/libnpjp2.so 20000'

Hope this helps.

[SOLVED] java.security.AccessControlException: access denied (java.net.SocketPermission host connect,resolve)

I am building a Java Applet which needs to connect to foreign host to operate. I created it and it runs good on OpenJDK Runtime Environment (IcedTea6 1.8pre) installed on my Ubuntu 10.04 Lucid Lynx Beta. But it does not run with Sun Java Runtime Environment 1.6.0_18 on Windows. I don’t know if it also does not work with Sun JRE in Linux. Also, as far as I know, OpenJDK/OpenJRE for Windows does not exist.

The applet shows somewhat this kind of when run in Windows under Sun JRE:

java.security.AccessControlException: access denied (java.net.SocketPermission host connect,resolve) 

and the page just stalls.

When I searched for help on the internet, I discovered that unsigned files do not run in Windows. So, I needed to sign it. The Certificate can cost at least a couple of hundred dollars for a month. If you are using it for commercial purposes, I advice you to buy a certificate. However, I just wanted my code to run in Windows and to do that I bundled the code inside a Jar file (I was just using the class file i.e. code=”Classname.class”. Now I need to use code=”Classname” archive=”JarName.jar” for applet in the HTML file.). So I am sharing what I did to make it run.

After building the Jar File (Netbeans IDE that I am using builds the Jar file automatically inside the dist sub-directory of the Project directory), I used the command

keytool -genkey

and entered the details. You can choose your own password for keystore. You can either use the same password for key password or choose a different one. Now a keyfile named .keystote is created in the home directory. I need to certify the key. Since I have not purchased a security certificate, I needed to certify it myself using the following command:

keytool -selfcert

. Now a key named mykey is created for me to use. This should only be done once.

Now, I changed my directory to the dist directory and executed the following command to sign a MyJarApplet.jar:

jarsigner -storepass KeySorePassword -keypass KeyPassPassword MyJarApplet.jar mykey

Here KeyStorePassword is the password used while creating the keystore and KeyPassPassword is the password used in the key mykey.

Now, the applet asks for authentication instead of showing nothing at all in Windows too.

Hope this helps.

References:
http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html
http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/jarsigner.html
http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/keytool.html