Java

From GeilThings

Jump to: navigation, search
Java
General
Version 7u21
Stable 7u25
Function Programming Language
Scripts
Version Script java -version

Contents


General

  • Version: java -version
    • Output:
    java version "1.6.0_29"
    Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02, mixed mode)
  • jps: Java Virtual Machine Process Status Tool - Lists the Java Virtual Machines for which it has access permissions on a host - http://download.oracle.com/javase/1.5.0/docs/tooldocs/share/jps.html

Installation

# Remove the java version that comes with CentOS. Is this OK???
yum remove java
# In CentOS 6.2, that is java-1.5.0-gcj
 
# http://www.java.com/en/download/help/linux_install.xml
# http://www.wikihow.com/Install-Java-on-Linux
 
wget http://download.oracle.com/otn-pub/java/jdk/6u25-b06/jdk-6u25-linux-x64.bin
mv jdk-6u25-linux-x64.bin\?e\=1310475018\&h\=9cb841a2dc5a669f9d1d67e1150c8b27 jdk-6u25-linux-x64.bin
# sh: Command interpreter
sh jdk-6u25-linux-x64.bin
## ...
## Press Enter to continue
## ...
# (wait some 15 sec)
## Done.
# From http://www.wikihow.com/Install-Java-on-Linux 
# 1. This installer will create its installation in the same folder, where the downloaded file was placed 
# and from where you have started the installation script. 
# 2. The java executable you need to launch is located in a subfolder, called 'bin'. This way of installation
# will not configure a default 'java' command for you: you must do this manually or always include 
# the full path in your startup script.
 
cd /usr/bin
 
ln -s /opt/jdk1.6.0_25/bin/java 
ln -s /opt/jdk1.6.0_25/bin/javac 
ln -s /opt/jdk1.6.0_25/bin/javadoc
 
# Create softlink to facilitate administration.
cd /opt
ln -s jdk1.6.0_25 /opt/java
 
#add to /etc/profile
PATH=$PATH:/opt/java/bin
export PATH
#add it also to the file /home/username/.bash_profile from the current user

Upgrade

1.7.x

  • Started with 1.7.4.


RAWNEWVERSION=`curl -sd "action=ask&query=[[Java]]|%3FStable&format=json" http://www.geilthings.com/api.php` 
NEWVERSION=`echo "$RAWNEWVERSION" | grep -Po '^.*?\K(?<=Stable\":\[\").*?(?=\")'`  
echo $NEWVERSION
 
# Download using a desktop browser and upload to server if server only runs in text mode.
# Site: http://www.oracle.com/technetwork/java/javase/downloads/index.html
# OR,
# The EXCELLENT solution for 7u3 from
# http://blog.kdecherf.com/2012/04/12/oracle-i-download-your-jdk-by-eating-magic-cookies/
# works. Thanks @Kevin Decherf.
cd /opt
wget --no-cookies ‘--no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjdk-${NEWVERSION}-download-1501626.html;" http://download.oracle.com/otn-pub/java/jdk/${NEWVERSION}-b11/jdk-${NEWVERSION}-linux-x64.rpm
mv jdk-${NEWVERSION}-linux-x64.rpm* jdk-${NEWVERSION}-linux-x64.rpm
 
cd /opt
rpm -Uvh jdk-${NEWVERSION}-linux-x64.rpm
# java will be installed to /usr/java/default/bin. 
# "default" is a sym link to the java version folder, e.g. jdk1.7.0_05
 
# Check java version
java -version
 
# Restart all java applications: Tomcat, HBase, Oracle NoSQL, Cassandra, Neo4j, ...


RAWNEWVERSION=`curl -d "action=ask&query=[[Java]]|%3FStable&format=json" http://www.geilthings.com/api.php` 
NEWVERSION=`echo "$RAWNEWVERSION" | grep -Po '^.*?\K(?<=Stable\":\[\").*?(?=\")'`  
echo $NEWVERSION
 
# Download using a desktop browser and upload to server if server only runs in text mode.
cd /opt
rpm -Uvh jdk-${NEWVERSION}-linux-x64.rpm
# java will be installed to /usr/java/default/bin. 
# "default" is a sym link to the java version folder, e.g. jdk1.7.0_04
 
# Modify old symbolic links since some java 1.6 links are NOT changed by rpm.
cd /usr/bin
# -f forces the "java" symlink to be changed to "/usr/java/default/bin/java"
ln -f -s /usr/java/default/bin/java 
ln -f -s /usr/java/default/bin/javac 
ln -f -s /usr/java/default/bin/javadoc
 
# Modify the soft link.
rm -f /opt/java
 
# Check if there is a JAVA_HOME variable in /etc/profile and /home/username/.bash_profile,
# modify them. 
export JAVA_HOME=/usr/java/default
# Same for PATH pointing to the java binaries. It should point now to /usr/java/default
PATH=$PATH:/usr/java/default/bin
 
# Either restart the ssh session or reload the /etc/profile file.
source /etc/profile
 
# Check java version
java -version
# Answer:
# java version "1.7.0_04"
# Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
# Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
 
# Restart all java applications: Tomcat, HBase, Oracle NoSQL, Cassandra, ...

Errors

Cassandra 1.1.0, Java 1.7.4, Could not create the Java Virtual Machine

Cassandra 1.1.0 could not be started and an error pops on the log file, "Could not create the Java Virtual Machine. A fatal exception has occurred. Program will exit.".


Solution: The stack size specified is too small, Specify at least 160k.

Modify the line below (..."128k"...) to reach a stack size of at least 160k in the file /opt/cassandra/conf/cassandra-env.sh

JVM_OPTS="$JVM_OPTS -Xss160k"

Error while upgrading Java using rpm

Unpacking JAR files...
        rt.jar...
Error: Could not open input file: /usr/java/jdk1.7.0_09/jre/lib/rt.pack
        jsse.jar...
Error: Could not open input file: /usr/java/jdk1.7.0_09/jre/lib/jsse.pack
        charsets.jar...
Error: Could not open input file: /usr/java/jdk1.7.0_09/jre/lib/charsets.pack
        tools.jar...
Error: Could not open input file: /usr/java/jdk1.7.0_09/lib/tools.pack
        localedata.jar...
Error: Could not open input file: /usr/java/jdk1.7.0_09/jre/lib/ext/localedata.pack

See the comments section below for 3 possible explanations of the errors.

Programming with Java


Versions

Software name Version number Version date
Java 7u10
7u11
7u13
7u15
7u17
7u21
14 December 2012
17 January 2013
2 February 2013
20 February 2013
7 March 2013
27 April 2013

Deprecated

Upgrading Java 1.6.x

  • Valid for 1.6.25 to 1.6.27 to 1.6.29 to 1.6.30 to 1.6.31:
cd /opt
 
# Java 1.6.x
# Install the new java version from .bin file
# wget http://download.oracle.com/otn-pub/java/jdk/6u29-b11/jdk-6u29-linux-x64.bin
wget http://download.oracle.com/otn-pub/java/jdk/6u31-b04/jdk-6u31-linux-x64.bin
 
# Rename the file if necessary, e.g.
# mv jdk-6u29-linux-x64.bin\?e\=1319296191\&h\=5a1389adf2f67da42ac0a593a261c289 jdk-6u29-linux-x64.bin
 
# Run the binary file.
sh jdk-6u31-linux-x64.bin
 
## ...
## Press Enter to continue
## ...
# (wait some 6-7 sec)
## Done.
 
NEWVERSION=1.6.0_31
OLDVERSION=1.6.0_30
 
# Modify symbolic links
 
cd /usr/bin
 
# -f forces the "java" symlink to be changed to "/opt/jdk_newversion/bin/java"
ln -f -s /opt/jdk${NEWVERSION}/bin/java 
ln -f -s /opt/jdk${NEWVERSION}/bin/javac 
ln -f -s /opt/jdk${NEWVERSION}/bin/javadoc
 
# Modify the soft link.
rm -f /opt/java
ln -s /opt/jdk${NEWVERSION} /opt/java
 
# Check if there is a JAVA_HOME variable in /etc/profile and /home/username/.bash_profile,
# modify them.
 
# Close the ssh session and restart it again so the new profile applies.
# ...
# Restart everything java, e.g.
# Tomcat, Cassandra, HBase, Oracle NoSQL.
# Restart apache web server.
# ...
# Test applications, including scala applications. 
 
NEWVERSION=1.6.0_31
OLDVERSION=1.6.0_30
cd /opt
mv jdk${OLDVERSION} jdk${OLDVERSION}_old
 
# Test again, and if everything ok,
# remove the old java directory and the new .bin file a few weeks later.
 
rm -rf jdk${OLDVERSION}_old/
rm -f jdk-6u29-linux-x64.bin

Comments

blog comments powered by Disqus