[jruby-user] FileUtils missing

112 views
Skip to first unread message

Charles Monteiro

unread,
Nov 13, 2012, 10:34:55 PM11/13/12
to Jruby Users List 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:



> C:\jruby-1.7.0\bin\jruby.exe --1.9 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) S:/Apps/IdeaProjects/Jruby/DataUploader/src/specs/test_jefferies_load.rb
> NameError: uninitialized constant FeedTransformer::ConfigurationReader::FileUtils
> const_missing at org/jruby/RubyModule.java:2678
> extract_misc at S:/Apps/IdeaProjects/Jruby/DataUploader/src/specs/../../src/lib/feed_management.rb:268
> initialize at S:/Apps/IdeaProjects/Jruby/DataUploader/src/specs/../../src/lib/feed_management.rb:257
> initialize at S:/Apps/IdeaProjects/Jruby/DataUploader/src/specs/../../src/lib/feed_management.rb:381
> (root) at S:/Apps/IdeaProjects/Jruby/DataUploader/src/specs/test_jefferies_load.rb:3
> load at org/jruby/RubyKernel.java:1045
> (root) at -e:1
>
> 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
jr...@smallruby.com




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Richie Vos

unread,
Nov 13, 2012, 10:46:56 PM11/13/12
to us...@jruby.codehaus.org
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 <jr...@smallruby.com> wrote:
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:


> C:\jruby-1.7.0\bin\jruby.exe --1.9 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) S:/Apps/IdeaProjects/Jruby/DataUploader/src/specs/test_jefferies_load.rb
> NameError: uninitialized constant FeedTransformer::ConfigurationReader::FileUtils
>   const_missing at org/jruby/RubyModule.java:2678
>    extract_misc at S:/Apps/IdeaProjects/Jruby/DataUploader/src/specs/../../src/lib/feed_management.rb:268
>      initialize at S:/Apps/IdeaProjects/Jruby/DataUploader/src/specs/../../src/lib/feed_management.rb:257
>      initialize at S:/Apps/IdeaProjects/Jruby/DataUploader/src/specs/../../src/lib/feed_management.rb:381
>          (root) at S:/Apps/IdeaProjects/Jruby/DataUploader/src/specs/test_jefferies_load.rb:3
>            load at org/jruby/RubyKernel.java:1045
>          (root) at -e:1
>
> 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.
 
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.

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?

Hirotsugu Asari

unread,
Nov 13, 2012, 11:18:29 PM11/13/12
to us...@jruby.codehaus.org

On Nov 13, 2012, at 10:46 PM, Richie Vos <ric...@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.

Thomas E Enebo

unread,
Nov 14, 2012, 1:42:18 PM11/14/12
to us...@jruby.codehaus.org
On Tue, Nov 13, 2012 at 9:34 PM, Charles Monteiro <jr...@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....@gmail.com
Reply all
Reply to author
Forward
0 new messages