# Trouble with java

**URL:** <https://discourse.chef.io/t/trouble-with-java/4434>\
**Category:** Chef Infra (archive)\
**Created:** [September 10, 2013, 9:15pm UTC](https://discourse.chef.io/t/trouble-with-java/4434 "2013-09-10T21:15:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_Ivey](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/alan_ivey/32/474_2.png) [@Alan\_Ivey](https://discourse.chef.io/u/Alan_Ivey)\
**Post date:** [September 10, 2013, 9:15pm UTC](https://discourse.chef.io/t/trouble-with-java/4434/1 "2013-09-10T21:15:46Z")

</div>

I loaded up the Jenkins cookbook, which requires Java. I’m getting this  
error the first time I run the java cookbook:

# ================================================================================ Recipe Compile Error in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/ echoditto\_site\_test.com/recipes/default.rb

## NoMethodError

undefined method `[]’ for nil:NilClass

## Cookbook Trace:

/tmp/vagrant-chef-1/chef-solo-1/cookbooks/java/recipes/default.rb:21:in  
`from_file' /tmp/vagrant-chef-1/chef-solo-1/cookbooks/jenkins/recipes/server.rb:28:in`from\_file’

/tmp/vagrant-chef-1/chef-solo-1/cookbooks/echoditto\_role\_jenkins/recipes/default.rb:14:in  
`from_file' /tmp/vagrant-chef-1/chef-solo-1/cookbooks/ echoditto_site_test.com/recipes/default.rb:40:in`from\_file’

## Relevant File Content:

/tmp/vagrant-chef-1/chef-solo-1/cookbooks/java/recipes/default.rb:

14: # Unless required by applicable law or agreed to in writing, software  
15: # distributed under the License is distributed on an “AS IS” BASIS,  
16: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or  
implied.  
17: # See the License for the specific language governing permissions and  
18: # limitations under the License.  
19: #  
20:  
21\>\> include\_recipe "java::#{node[‘java’][‘install\_flavor’]}"  
22:  
23: # Purge the deprecated Sun Java packages if  
remove\_deprecated\_packages is true  
24: %w[sun-java6-jdk sun-java6-bin sun-java6-jre].each do |pkg|  
25: package pkg do  
26: action :purge  
27: only\_if { node[‘java’][‘remove\_deprecated\_packages’] }  
28: end  
29: end  
30:

[2013-09-10T20:58:46+00:00] DEBUG: Re-raising exception: NoMethodError -  
undefined method `[]’ for nil:NilClass

It’s behaving as if none of the attribute files are being loaded. If I add  
node[‘java’][‘install\_flavor’] = openjdk (I’m on CentOS), I get another  
error about an attribute being null. Repeat, repeat…

I’m using chef-solo and I have ‘depends java’ in my cookbook. Any ideas?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Alan\_Ivey](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/alan_ivey/32/474_2.png) [@Alan\_Ivey](https://discourse.chef.io/u/Alan_Ivey)\
**Post date:** [September 11, 2013, 4:07pm UTC](https://discourse.chef.io/t/trouble-with-java/4434/2 "2013-09-11T16:07:47Z")

</div>

Sigh, it was a simple mistake; missed a 'depends' in a role cookbook of  
another role cookbook.

On Tue, Sep 10, 2013 at 5:15 PM, Alan Ivey [alan@echoditto.com](mailto:alan@echoditto.com) wrote:

> I loaded up the Jenkins cookbook, which requires Java. I'm getting this  
> error the first time I run the java cookbook:
> 
> ================================================================================  
> Recipe Compile Error in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/  
> echoditto\_site\_test.com/recipes/default.rb
> 
> ================================================================================
> 
> ## NoMethodError
> 
> undefined method `' for nil:NilClass
> 
> ## Cookbook Trace:
> 
> /tmp/vagrant-chef-1/chef-solo-1/cookbooks/java/recipes/default.rb:21:in  
> `from\_file'
> 
> /tmp/vagrant-chef-1/chef-solo-1/cookbooks/jenkins/recipes/server.rb:28:in  
> `from\_file'
> 
> /tmp/vagrant-chef-1/chef-solo-1/cookbooks/echoditto\_role\_jenkins/recipes/default.rb:14:in  
> `from_file' /tmp/vagrant-chef-1/chef-solo-1/cookbooks/ echoditto_site_test.com/recipes/default.rb:40:in `from\_file'
> 
> ## Relevant File Content:
> 
> /tmp/vagrant-chef-1/chef-solo-1/cookbooks/java/recipes/default.rb:
> 
> 14: # Unless required by applicable law or agreed to in writing, software  
> 15: # distributed under the License is distributed on an "AS IS" BASIS,  
> 16: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or  
> implied.  
> 17: # See the License for the specific language governing permissions and  
> 18: # limitations under the License.  
> 19: #  
> 20:  
> 21\>\> include\_recipe "java::#{node['java']['install\_flavor']}"  
> 22:  
> 23: # Purge the deprecated Sun Java packages if  
> remove\_deprecated\_packages is true  
> 24: %w[sun-java6-jdk sun-java6-bin sun-java6-jre].each do |pkg|  
> 25: package pkg do  
> 26: action :purge  
> 27: only\_if { node['java']['remove\_deprecated\_packages'] }  
> 28: end  
> 29: end  
> 30:
> 
> [2013-09-10T20:58:46+00:00] DEBUG: Re-raising exception: NoMethodError -  
> undefined method `' for nil:NilClass
> 
> It's behaving as if none of the attribute files are being loaded. If I add  
> node['java']['install\_flavor'] = openjdk (I'm on CentOS), I get another  
> error about an attribute being null. Repeat, repeat...
> 
> I'm using chef-solo and I have 'depends java' in my cookbook. Any ideas?  
> Thanks!
