Java Runtime 7 update 60 issue with Extension Attribute

tthurman
Contributor III

Hey guys,

I was updating my image recently and I decided to move to Java Runtime 7. I noticed that after I started using this, the Extension Attribute stops working, or rather it reports as not installed even though it is.

This is the EA that I'm using:

#!/bin/sh

#Check if java_home is defined
javaHome=`/usr/libexec/java_home 2> /dev/null`;

if [ ! -z $javaHome ]
then
vers=`java -version 2>&1 | grep "java version" | awk '{print substr($3,2,length($3)-2);}'`
echo "<result>$vers</result>"
else
echo "<result>Not Installed</result>"
fi

I think I know what the problem is, I just don't know how to fix it.
It seems that when it tries to run "java -version" from terminal it fails because we don't install the JDK. (If I go to terminal and type "java -version" it attempts to give the site to install the JDK).

We would rather not install the JDK as well, unless necessary.

Anyone have any thoughts?

Sincerely,
TJ

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

I've seen this as well recently on a Mac that did not have the JDK installed. Only thing I can recommend is changing the Extension Attribute to pull the version string from the Info.plist for the Internet Plug-In

#!/bin/sh

#Check if java_home is defined
javaHome=`/usr/libexec/java_home 2> /dev/null`;

if [ ! -z $javaHome ]
then
vers=`defaults read /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist CFBundleVersion`
echo "<result>$vers</result>"
else
echo "<result>Not Installed</result>"
fi

Note that the above will return something like:

1.7.60.19

If you change CFBundleVerison to CFBundleShortVersionString, you get a more human readable:

Java 7 Update 60

Choice is yours on which to use. The former will be closer to what the java -version command was previously pulling, but not actually the same thing.

View solution in original post

2 REPLIES 2

mm2270
Legendary Contributor III

I've seen this as well recently on a Mac that did not have the JDK installed. Only thing I can recommend is changing the Extension Attribute to pull the version string from the Info.plist for the Internet Plug-In

#!/bin/sh

#Check if java_home is defined
javaHome=`/usr/libexec/java_home 2> /dev/null`;

if [ ! -z $javaHome ]
then
vers=`defaults read /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist CFBundleVersion`
echo "<result>$vers</result>"
else
echo "<result>Not Installed</result>"
fi

Note that the above will return something like:

1.7.60.19

If you change CFBundleVerison to CFBundleShortVersionString, you get a more human readable:

Java 7 Update 60

Choice is yours on which to use. The former will be closer to what the java -version command was previously pulling, but not actually the same thing.

tthurman
Contributor III

Brilliant!

Thank you so much! This was what I was going to try to do after brainstorming for a bit.

Much appreciated, sir.

Cheers!