How may I determine Java version from inside the Chef custom resource without passing it as a parameter?

151 views Asked by At

I am creating a custom resource and would like to make it as self-contained as possible. I need to determine java version that is going to be available on the node so I will be able to setup JAVA_OPTS variable properly, depending on Java version. I would prefer to find this out without making resource's client to pass this information as a parameter. Could you please suggest me some solutions?

Kind regards,
Denuil

1

There are 1 answers

1
coderanger On BEST ANSWER

Use the shell_out! helper method to run java -version and parse the output. You can look at the data in the Ohai languages plugin which does already check some of this for you.