Do you use the java cookbook community ?
It includes LWRP for this purpose:
java_alternatives "set java alternatives" do
java_location '/usr/local/java'
bin_cmds ["java", "javac"]
action :set
end
Update: shell cookbook example "my_java"
The following is an example cookbook called "my_java" designed to install Oracle JDK on Ubuntu:
├── attributes
│ └── java.rb <-- Used for java cookbook attribute overrides
├── Berksfile
├── Berksfile.lock
├── metadata.rb
├── README.md
└── recipes
└── default.rb
- JDK
$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
:
metadata.rb
name 'my_java'
maintainer 'Mark O''Connor'
maintainer_email 'XXXXXXXXXXXXXXX'
license 'All rights reserved'
description 'Installs/Configures my_java'
long_description 'Installs/Configures my_java'
version '0.1.0'
depends "apt"
depends "java"
/java.rb
normal['java']['jdk_version'] = '8'
normal['java']['install_flavor'] = 'oracle'
normal['java']['oracle']['accept_oracle_download_terms'] = true
:
- java openJDK. v8 OracleJDK
/default.rb
include_recipe "apt"
include_recipe "java"
:
- , "apt" Linux Debian. redhat.