How to set JAVA_HOME AND PATH in linux and windows while writing chef cookbook

Cookbook for Linux:

execute "export JAVA_HOME" do
command "export JAVA_HOME=#{jdk_java_home}"
end

execute "export" do
command "export PATH=#{jdk_path}"
end

Path for linux:

JAVA_HOME = /home/oracleweblogic/wls/jdk1.8.0_211
PATH=$PATH:/home/oracleweblogic/wls/jdk1.8.0_211/bin

Cookbook for windows:

windows_env 'setpath' do
value "#{jdkwindows_java_home}"
end

path for windows:

set path="C:\Program Files\ Java\jdk1.8.0_211\bin

when Iam trying this code it throws error that the java home path is not set properly and is there any resource block particulary available in chef for setting javahome or else how to set the path properly

Can u help me in this?

Thanks in advance

The "command" you are running is run in a different shell than other commands you may run later in your cookbook. The information is thus discarded. You either need to run those exports inside whatever commands you are running, or use environment settings

execute "myrealcommand" do
environment t hash of JAVA settings ]
command "myrealcommand"
end

Thanks for your valuable answer