Skip to content

Instantly share code, notes, and snippets.

@petems
Last active September 25, 2015 11:24
Show Gist options
  • Save petems/fa98a6afb067ca9fca0a to your computer and use it in GitHub Desktop.
Save petems/fa98a6afb067ca9fca0a to your computer and use it in GitHub Desktop.
Java command on OSX with and without installation
After installation:
==> Downloading http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-macosx-
######################################################################## 100.0%
==> Running installer for java; your password may be necessary.
==> installer: Package name is JDK 8
==> installer: Installing at base path /
==> installer: The install was successful.
🍺 java installed to '/opt/homebrew-cask/Caskroom/java/1.8.0' (5 files, 208M)
vagrant:~ vagrant$ puppet apply foo.pp
Notice: Scope(Class[main]): Java version is 1.8.0
Notice: Compiled catalog for vagrant.home in environment production in 0.01 seconds
Notice: Finished catalog run in 0.02 seconds
vagrant:~ vagrant$ cat foo.pp
notice("Java version is ${::java_version}")
vagrant:~ vagrant$ puppet apply foo.pp
Could not retrieve fact='java_version', resolution='<anonymous>': undefined method `strip' for nil:NilClass
Could not retrieve fact='java_version', resolution='<anonymous>': undefined method `strip' for nil:NilClass
Could not retrieve fact='java_version', resolution='<anonymous>': undefined method `strip' for nil:NilClass
Warning: Scope(Class[main]): Could not look up qualified variable '::java_version';
Notice: Scope(Class[main]): Java version is
Notice: Compiled catalog for vagrant.home in environment production in 0.01 seconds
Notice: Finished catalog run in 0.01 seconds
Facter.add(:java_version) do
confine :operatingsystem => 'Darwin'
has_weight 100
setcode do
unless /Unable to find any JVMs matching version/ =~ Facter::Util::Resolution.exec('/usr/libexec/java_home --failfast 2>&1')
Facter::Util::Resolution.exec('java -Xmx8m -version 2>&1').lines.first.split(/"/)[1].strip
end
end
end
vagrant:~ vagrant$ java
No Java runtime present, requesting install.
vagrant:~ vagrant$ /usr/libexec/java_home --failfast
Unable to find any JVMs matching version "(null)".
vagrant:~ vagrant$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment