Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

I found a very useful link
http://www.jayway.com/2014/01/15/how-to-switch-jdk-version-on-mac-os-x-maverick/

I added the following to my .profile and typed setjdk 1.7 at the command prompt. Problem solved.

function setjdk() {  
  if [ $# -ne 0 ]; then  
   removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'  
   if [ -n "${JAVA_HOME+x}" ]; then  
    removeFromPath $JAVA_HOME  
   fi  
   export JAVA_HOME=`/usr/libexec/java_home -v $@`  
   export PATH=$JAVA_HOME/bin:$PATH  
  fi  
 }  
 function removeFromPath() {  
  export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")  
 }

I have the following JDKs setup on my Mac with OSX 10.10.5 in /Library/Java/JavaVirtualMachines.

drwxr-xr-x  3 root  wheel  102 Jul 14 17:52 1.6.0.jdk
drwxr-xr-x  3 root  wheel  102 Jul  2 20:01 jdk1.8.0_45.jdk
drwxr-xr-x  3 root  wheel  102 Nov 13  2014 jdk1.8.0_25.jdk
drwxr-xr-x  3 root  wheel  102 Oct 28  2013 jdk1.7.0_45.jdk

As you can see from the following, it does work

dimac0001:~ norrisshelton$ setjdk 1.6
cdimac0001:~ norrisshelton$ java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-468-11M4833)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-468, mixed mode)
cdimac0001:~ norrisshelton$
cdimac0001:~ norrisshelton$
cdimac0001:~ norrisshelton$ setjdk 1.7
cdimac0001:~ norrisshelton$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
cdimac0001:~ norrisshelton$
cdimac0001:~ norrisshelton$
cdimac0001:~ norrisshelton$ setjdk 1.8
cdimac0001:~ norrisshelton$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Go to the Oracle JDK download page to get the latest version of java. The page is currently located at http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

March 3rd, 2014

Posted In: Bash, OS/X

Tags: , , ,

Leave a Comment

Your environment (env) isn’t the same environment you get when you ssh into a machine. It isn’t even the same environment you get when you rlogin into the same machine. Consider [sourcdcode language=”bash”]ssh host env[/sourcecode]. The list is much shorter.

To add to the ssh environment, modify

~/.ssh/environment

on the target host and add in the properties:

JAVA_HOME=$JAVA_HOME

Then turn on the ability to have a user defined ssh environment by modifying

/etc/ssh/sshd_config

Change “PermitUserEnvironment no” to “… yes”. You will then need to bounce the ssh service. It looks like the following commands should work:

/etc/init.d/sshd [restart | start | stop]

January 11th, 2011

Posted In: Bash, SSH

Leave a Comment

LinkedIn Auto Publish Powered By : XYZScripts.com