Forum: JRuby FileUtils missing

Posted by Charles Monteiro (Guest)
on 2012-11-14 04:36
(Received via mailing list)
On my Windows box for the same exact project which works fine on my Mac 
OS X box and on my Windows tablet I get the following error:



> Process finished with exit code 1
I'm trying to make a call to FileUtils from within an inner class but 
the Jruby compiler is getting confused and again just on my Windows box 
? From the error it seems that the compiler wants to treat FileUtils as 
if  it was within the namespace of my inner class.  That fact that it 
works on my Mac and Win tablets suggests to me that I must have some 
sort of setup wrong and possibly with Java SDK. Given that,  I went 
ahead and downloaded the latest JDK from Oracle i.e. jdk 7 update 9 , 
setup JAVA_HOME to point to it as I had done on my win tablet where 
things work fine.  Unfortunately that did not work. If I go ahead and 
require "FileUtils" then I don't' get the error and the code works 
except for a warning:

C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:93: warning: already initialized 
constant OPT_TABLE
C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1268: warning: already 
initialized constant S_IF_DOOR
C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1496: warning: already 
initialized constant DIRECTORY_TERM
C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1500: warning: already 
initialized constant SYSCASE
C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1619: warning: already 
initialized constant LOW_METHODS
C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1625: warning: already 
initialized constant METHODS

which I find odd because I thought that Jruby is self contained i.e. ti 
doesn't go out of itself for Ruby functionality.

I'm a newbie, it seems that I may not understand the inter play between 
Ruby and Jruby and Java for that matter.

BTW, all of this is running Intellij IDEA which seems to be what JRuby 
central uses for development.

In conclusion, what possibly can be different in one environment from 
another that would create the conditions that would correlate to what I 
have described above ?

thanks again for the feedback.



Charles Monteiro
jruby@smallruby.com
Posted by Richie Vos (Guest)
on 2012-11-14 04:48
(Received via mailing list)
Some inline responses, but the proper way to load the FileUtils code is 
do:

require 'fileutils'


The require 'FileUtils' version you're doing works because macs and 
windows
boxes are case insensitive when handling file names. However ruby isn't, 
so
require 'fileutils' and then require 'FileUtils' leads to it being 
loaded
twice.

On Tue, Nov 13, 2012 at 9:34 PM, Charles Monteiro 
<jruby@smallruby.com>wrote:

> >    extract_misc at
> > Process finished with exit code 1
>
> I'm trying to make a call to FileUtils from within an inner class but the
> Jruby compiler is getting confused and again just on my Windows box ? From
> the error it seems that the compiler wants to treat FileUtils as if  it was
> within the namespace of my inner class.


That's just ruby's way of saying "I don't know what FileUtils is". Ruby
defaults to trying to find your class in the closest scope it can (eg
nested near whatever modules/classes the code you're running is in).


> That fact that it works on my Mac and Win tablets suggests to me that I
> must have some sort of setup wrong and possibly with Java SDK.


Someone may correct me, but I'd be pretty surprised if this had anything 
to
do with your java version. This is an issue in ruby land.


> C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1496: warning: already initialized
>
See my initial blurb for why this is happening. You can reproduce this 
on
your other machine by doing:

require 'fileutils'
require 'FileUtils' # will drop the warnings
require 'FIleUtils # will drop the warnings'

And also, that warning just means you're trying to set a constant that's
already been set. That happens because when the require runs multiple
times, the code in that file runs, and that code happens to set some
constants.

In conclusion, what possibly can be different in one environment from
> another that would create the conditions that would correlate to what I
> have described above ?
>

Try putting require 'fileutils' in your script, and see if you get the 
same
behavior. I'm not sure why you're not seeing weirdness on your mac, how 
do
you run the script there?
Posted by Hirotsugu Asari (Guest)
on 2012-11-14 05:19
(Received via mailing list)
On Nov 13, 2012, at 10:46 PM, Richie Vos <richie@groupon.com> wrote:

> Some inline responses, but the proper way to load the FileUtils code is do:
>
> require 'fileutils'
>
> The require 'FileUtils' version you're doing works because macs and windows 
boxes are case insensitive when handling file names. However ruby isn't, so 
require 'fileutils' and then require 'FileUtils' leads to it being loaded twice.

Just FYI: HFS+, which is *still* the default for the Mac OS X, can be 
case-sensitive or insensitive. It is not an OS issue. Assuming it is, or 
it isn't, can surprise you when you least expect it.
Posted by Thomas E Enebo (Guest)
on 2012-11-14 19:43
(Received via mailing list)
On Tue, Nov 13, 2012 at 9:34 PM, Charles Monteiro <jruby@smallruby.com> 
wrote:
> If I go ahead and require "FileUtils" then I don't' get the error and the code 
works except for a warning:
>
> C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:93: warning: already initialized constant 
OPT_TABLE
> C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1268: warning: already initialized 
constant S_IF_DOOR
> C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1496: warning: already initialized 
constant DIRECTORY_TERM
> C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1500: warning: already initialized 
constant SYSCASE
> C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1619: warning: already initialized 
constant LOW_METHODS
> C:/Ruby193/lib/ruby/1.9.1/FileUtils.rb:1625: warning: already initialized 
constant METHODS
>

Yeah this is odd as it implies you are loading fileutils from C Ruby's
1.9 directory and not JRuby's.  You likely have some ENV var set which
is causing you to load their stdlib rather than ours.  This is an
independent issue from what others have already mentioned.

-Tom

--
blog: http://blog.enebo.com       twitter: tom_enebo
mail: tom.enebo@gmail.com
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.