Skip to content

jarify with fxml: require_relative doesn't work from inside a jarfile #117

@brucetesar

Description

@brucetesar

Issue
After jarifying samples\fxml\Demo.rb, executing the jar file produces a LoadError for the require_relative statement in Demo.rb (around line 21). More precisely, the line
require_relative 'complex_control'
results in the error message
LoadError: no such file to load -- classpath:C:/complex_control

My guess is that this has something to do with the behavior of __FILE__ inside of a jar. If require_relative is implemented by referring to __FILE__, and __FILE__ doesn't behave properly inside a jar, that would help explain the trouble. The drive designation "C:" that appears in the error message does not appear when I call __FILE__, so I don't know where that comes from.

Workaround
In Demo.rb, replace the line
require_relative 'complex_control'
with the following lines:

    if JRubyFX::Application.in_jar? then
      require 'complex_control'
    else
      require_relative 'complex_control'
    end

In the jar execution, using require seems to work. I have not tried to test this with instances of require_relative anywhere else (for instance in a file in a directory below the root of the jar file).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions