# Gem::Platform::Java Uninitialized Constant

**URL:** <https://www.ruby-forum.com/t/gem-java-uninitialized-constant/235818>\
**Category:** JRuby\
**Created:** [July 17, 2013, 5:06pm UTC](https://www.ruby-forum.com/t/gem-java-uninitialized-constant/235818 "2013-07-17T17:06:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [July 17, 2013, 5:06pm UTC](https://www.ruby-forum.com/t/gem-java-uninitialized-constant/235818/1 "2013-07-17T17:06:48Z")

</div>

All -

I’m creating a gem whose dependencies differ by platform – if MRI Ruby,  
it  
needs to require rjb, and if JRuby, it very much needs not to require  
rjb.

In my gemspec file, I have something like this:

if /java/ === RUBY\_PLATFORM  
spec.platform = Gem::Platform::JAVA  
end

However, when I gem build this gemspec in JRuby, I get this error:

Invalid gemspec in [mygem.gemspec]: uninitialized constant  
Gem::Platform::JAVA

I also get that error for MSWIN. In pry, I can see that the constants  
do  
exist:

[8] pry(main)\> cd Gem::Platform  
[9] pry(Gem::Platform):1\> ls  
constants: CURRENT JAVA MINGW MSWIN RUBY  
Gem::Platform.methods: local match new  
Gem::Platform#methods:  
== === =~ \_deprecated\_empty? cpu cpu= empty? eql? hash  
inspect  
os os= to\_a to\_s version version=  
instance variables: @local  
locals: \_ \_\_ _dir __ex__ file __in__ out__pry_

Anyone know what’s going on here? My ultimate goal is to have a gem  
that’s  
dependent on this one install the one appropriate to the platform, and  
itself have an MRI and JRuby version.

Thanks for any help,  
Keith

---

<div class="post-metadata">

**Author:** ![islepilot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ac8455/32.png) [@islepilot](https://www.ruby-forum.com/u/islepilot)\
**Post date:** [July 17, 2013, 5:20pm UTC](https://www.ruby-forum.com/t/gem-java-uninitialized-constant/235818/2 "2013-07-17T17:20:14Z")

</div>

On Wed, Jul 17, 2013 at 4:05 PM, Keith B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> Gem::Platform::JAVA

quick fix would be to use the string “java”

- christian

BTW: my ruby2 does not have Gem::Platform::JAVA either - which does not  
mean much since today is the first time I use ruby2

---

<div class="post-metadata">

**Author:** ![islepilot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ac8455/32.png) [@islepilot](https://www.ruby-forum.com/u/islepilot)\
**Post date:** [July 17, 2013, 5:27pm UTC](https://www.ruby-forum.com/t/gem-java-uninitialized-constant/235818/3 "2013-07-17T17:27:50Z")

</div>

Hi Keith,

I don’t see a Gem::Platform::JAVA when running under plain JRuby 1.7.4:

jruby-1.7.4 :001 \> RUBY\_PLATFORM  
=\> “java”  
jruby-1.7.4 :003 \> Gem::VERSION  
=\> “1.8.24”  
jruby-1.7.4 :004 \> Gem::Platform::JAVA  
NameError: uninitialized constant Gem::Platform::JAVA  
from org/jruby/RubyModule.java:2631:in `const_missing' from (irb):5:in `evaluate’  
from org/jruby/RubyKernel.java:1093:in `eval' from org/jruby/RubyKernel.java:1489:in `loop’  
from org/jruby/RubyKernel.java:1254:in `catch' from org/jruby/RubyKernel.java:1254:in `catch’  
from /Users/rsutphin/.rvm/rubies/jruby-1.7.4/bin/irb:13:in `(root)’

I also don’t see it when grepping the source for rubygems.

Perhaps Gem::Platform::JAVA is something introduced by something that’s  
loaded in the pry environment but not from a general gem install  
environment? Or perhaps there are different versions of rubygems  
involved.

HTH,  
Rhett

From: Keith B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Reply-To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Wednesday, July 17, 2013 10:05 AM  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: [jruby-user] Gem::Platform::Java Uninitialized Constant

---

<div class="post-metadata">

**Author:** ![islepilot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ac8455/32.png) [@islepilot](https://www.ruby-forum.com/u/islepilot)\
**Post date:** [July 17, 2013, 5:37pm UTC](https://www.ruby-forum.com/t/gem-java-uninitialized-constant/235818/4 "2013-07-17T17:37:11Z")

</div>

That’s the irony. It _does_ have it – it just can’t be specified (see  
pry  
output below, running MRI 2.0).

I know I can specify “java”, I was doing that before, but I’m skeptical  
that something normally requiring a composite object can be assigned  
only  
one of those elements, and still work properly. I’m having problems  
getting platform detection and installation of the proper platform’s gem  
working properly, and I thought cleaning up this issue might help.

Thanks,  
Keith

[1] pry(main)\> cd Gem::Platform::JAVA  
[2] pry(#Gem::Platform):1\> ls  
Gem::Platform#methods: == === =~ cpu cpu= eql? hash inspect os  
os=  
to\_a to\_s version version=  
self.methods: **pry**  
instance variables: @cpu@os@version  
locals: \_ \_\_ _dir __ex__ file __in__ out__pry_  
[3] pry(#Gem::Platform):1\> to\_s  
=\> “java”  
[4] pry(#Gem::Platform):1\> @cpu  
=\> nil  
[5] pry(#Gem::Platform):1\> @os  
=\> “java”  
[6] pry(#Gem::Platform):1\> @version  
=\> nil  
[7] pry(#Gem::Platform):1\> RUBY\_VERSION  
=\> “2.0.0”

---

<div class="post-metadata">

**Author:** ![islepilot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ac8455/32.png) [@islepilot](https://www.ruby-forum.com/u/islepilot)\
**Post date:** [July 17, 2013, 5:41pm UTC](https://www.ruby-forum.com/t/gem-java-uninitialized-constant/235818/5 "2013-07-17T17:41:17Z")

</div>

Rhett -

You’re right! It didn’t occur to me that the platforms might differ by  
platform. 😉

This would be a JRuby bug, right?:

JRuby Gem::Platform Constants:

constants: CURRENT\_SPECIFICATION\_VERSION MARSHAL\_FIELDS  
NONEXISTENT\_SPECIFICATION\_VERSION TODAY

MRI Ruby 1.9.3 Gem::Platform Constants:

constants: CURRENT JAVA MINGW MSWIN RUBY

- Keith

---

<div class="post-metadata">

**Author:** ![islepilot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ac8455/32.png) [@islepilot](https://www.ruby-forum.com/u/islepilot)\
**Post date:** [July 17, 2013, 5:50pm UTC](https://www.ruby-forum.com/t/gem-java-uninitialized-constant/235818/6 "2013-07-17T17:50:38Z")

</div>

Hi Keith,

Gem::Platform::JAVA doesn’t exist in my install of 1.9.3-p448, either:

1.9.3p448 :001 \> RUBY\_PLATFORM  
=\> “x86\_64-darwin12.4.1”  
1.9.3p448 :002 \> Gem::VERSION  
=\> “1.8.25”  
1.9.3p448 :003 \> Gem::Platform::JAVA  
NameError: uninitialized constant Gem::Platform::JAVA  
from (irb):4  
from /Users/rsutphin/.rvm/rubies/ruby-1.9.3-p448/bin/irb:16:in  
`’

I think there’s something getting pulled into the environment where you  
are running pry for 1.9.3 that’s adding the JAVA constant. It looks like  
bundler is one possible culprit:

1.9.3p448 :004 \> require ‘bundler’  
=\> true  
1.9.3p448 :005 \> Gem::Platform::JAVA  
=\> #\<Gem::Platform:0x3fdfa2cf5a3c @cpu=nil, @os=“java”, @version=nil\>

So you shouldn’t rely on that constant in your gemspec. The only  
constant  
that rubygems itself defines is Gem::Platform::RUBY, and that’s just the  
string “ruby”. I think that using the string “java” is what’s expected  
I  
can back up kristian in saying that “java” definitely works. If you look  
at the source for Gem::Platform, you can see where it maps from the  
string  
to the composite object.

Rhett

From: Keith B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Reply-To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Wednesday, July 17, 2013 10:39 AM  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: [jruby-user] Gem::Platform::Java Uninitialized Constant

---

<div class="post-metadata">

**Author:** ![islepilot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ac8455/32.png) [@islepilot](https://www.ruby-forum.com/u/islepilot)\
**Post date:** [July 17, 2013, 8:34pm UTC](https://www.ruby-forum.com/t/gem-java-uninitialized-constant/235818/7 "2013-07-17T20:34:52Z")

</div>

Ok, guys, you have definitively answered my question now. I’ll use  
“java”.

Thanks,  
Keith

---

<div class="post-metadata">

**Author:** ![islepilot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/ac8455/32.png) [@islepilot](https://www.ruby-forum.com/u/islepilot)\
**Post date:** [July 17, 2013, 6:08pm UTC](https://www.ruby-forum.com/t/gem-java-uninitialized-constant/235818/8 "2013-07-17T18:08:45Z")

</div>

It seems like something on your system is introducing those constants.  
Do  
you have any pry plugins or a .pryrc file or anything?

$ rbenv version  
2.0.0-rc2

$ pry  
[1] pry(main)\> cd Gem::Platform  
[2] pry(Gem::Platform):1\> ls  
constants: CURRENT RUBY  
Gem::Platform.methods: local match new  
Gem::Platform#methods:  
== =~ cpu= hash os to\_a version  
=== cpu eql? inspect os= to\_s version=  
instance variables: @local  
locals: \_ \_\_ _dir __ex__ file __in__ out__pry_  
[3] pry(Gem::Platform):1\>  
[4] pry(main)\>

$ rbenv version  
jruby-1.7.4

$ pry  
[1] pry(main)\> cd Gem::Platform  
[2] pry(Gem::Platform):1\> ls  
constants: CURRENT RUBY  
Gem::Platform.methods: local match new  
Gem::Platform#methods:  
== =~ cpu empty? hash os to\_a version  
=== \_deprecated\_empty? cpu= eql? inspect os= to\_s version=  
instance variables: @local  
locals: \_ \_\_ _dir __ex__ file __in__ out__pry_  
[3] pry(Gem::Platform):1\>

$ rbenv version  
1.9.3-p327

$ pry  
[1] pry(main)\> RUBY\_VERSION  
=\> “1.9.3”  
[2] pry(main)\> cd Gem::Platform  
[3] pry(Gem::Platform):1\> ls  
constants: CURRENT RUBY  
Gem::Platform.methods: local match new  
Gem::Platform#methods:  
== =~ cpu empty? hash os to\_a version  
=== \_deprecated\_empty? cpu= eql? inspect os= to\_s version=  
instance variables: @local  
locals: \_ \_\_ _dir __ex__ file __in__ out__pry_  
[4] pry(Gem::Platform):1\>

There are techniques for doing what you want though. Check out How do I  
make a gem that targets both MRI and  
JRuby?[http://stackoverflow.com/a/13540730/1200100](http://stackoverflow.com/a/13540730/1200100)for instance.
