Skip to content

require_relative does not work inside a jar on Windows #4188

@presidentbeef

Description

@presidentbeef

This is a followup to #4000, the fix for which I believe was incomplete: d4cbfd2 I think the issue below is due to the path starting with classpath:c:/ instead of classpath:/

Environment

JRuby 9.1.5.0 complete jar.

Windows 8.1.

java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

Expected Behavior

Load files in jar using require_relative.

Actual Behavior

> java -jar myapp.jar
LoadError: no such file to load -- classpath:C:/lib/test
           require at org/jruby/RubyKernel.java:956
  require_relative at uri:classloader:/jruby/kernel/kernel.rb:13
            <main> at classpath:/jar-bootstrap.rb:1

Steps to reproduce

Use https://github.com/presidentbeef/jruby-realpath-error

I happened to have a jruby-complete jar in ~/.jruby-jar/ so I use that below to build the jar on Linux. I'm not sure the Linux part is necessary, but that's where I started.

git clone https://github.com/presidentbeef/jruby-realpath-error.git
cd jruby-realpath-error
cp ~/.jruby-jar/jruby-complete-9.1.5.0.jar myapp.jar
jar ufe myapp.jar org.jruby.JarBootstrapMain jar-bootstrap.rb lib/test.rb

Copy jar to a Windows machine and run it:

java -jar myapp.jar

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions