Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When inside a .JAR, __FILE__ returns a URI-like string that isn't understood by some keywords #1100

Closed
mauricioszabo opened this Issue Oct 8, 2013 · 5 comments

Comments

Projects
None yet
3 participants
@mauricioszabo
Copy link

commented Oct 8, 2013

I'm facing a strange problem when I'm using JRuby + Warbler: I'm packing a JRuby program inside a .jar file. But when the path that the JAR is contains spaces, File.dirname(__FILE__) returns some kind of URI to the file like the following:

jar:file:/tmp/Directory%20with%20spaces/my-program.jar!/my-program/lib/boot.rb

These "%20" confuses some commands like require_relative (it don't work at all), or File.read[lines] (don't work either). Somehow, require works fine.

A workaround that I did is to create a URI.unescape(File.dirname(__FILE__)), but I don't know if this can lead to problems if, for instance, the file that I'm trying to read has %20 on its filename.

@headius

This comment has been minimized.

Copy link
Member

commented Oct 10, 2013

Yeah, not all methods in the system recognize URLs. It's a standing task to unify file-aware methods to know about URLs, and we've been adding support a piece at a time.

So, summarizing this issue:

  • require_relative does not work with URLs. This is probably a higher priority, since require already works.
  • File.read and other methods that open files do not work with URLs. This is lower priority, but may simply require handling of URLS in File's open logic.
@mauricioszabo

This comment has been minimized.

Copy link
Author

commented Oct 10, 2013

When I tried to debug this issue, require_relative and File.read had become confused with these %20 (the URI representation of space). When I remove them and substitute with spaces, everything works fine. Maybe there is a way to expose to JRuby the URI without these %20, so there would be no need to change code on require_relative or File.read.

@ghost

This comment has been minimized.

Copy link

commented Nov 18, 2013

'require' also has this error when the gem is packaged in jar as resource when using jruby 1.7.8.
Changing to some path that doesn't have space solves the problem.

Here is part of stacktrace:

LoadError: no such file to load -- jar:file:C:/Documents%20and%20Settings/works/.m2/repository/some-folder/oss/compass-maven-plugin/0.0.1/compass-maven-plugin-0.0.1.jar!/gems/sass-3.2.12/lib/sass/../sass
require at org/jruby/RubyKernel.java:1084
require at file:/C:/Documents and Settings/works/.m2/repository/org/jruby/jruby-complete/1.7.8/jruby-complete-1.7.8.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:55

@ratnikov

This comment has been minimized.

Copy link
Contributor

commented Mar 2, 2014

I've tried to reproduce the issue in ubuntu, but it seems to work:

$ bin/jruby -e 'require "jar:file:/tmp/dir with space/test.jar!/foo/test.rb"'
File: file:/tmp/dir with space/test.jar!/foo/test.rb, dirname: "file:/tmp/dir with space/test.jar!/foo"

I'll try to verify it with windows system as well, but could any if you guys make sure that there is still an issue with recently released 1.7.11 release? You can download the jar I used here: https://drive.google.com/file/d/0B3EcYC59OaVjN21mTm92UVFnX0k/edit?usp=sharing

@mauricioszabo

This comment has been minimized.

Copy link
Author

commented Apr 11, 2014

I think it is working right now, so we can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.