-
-
Notifications
You must be signed in to change notification settings - Fork 942
Closed
Description
If I load a file from the classpath like this:
private Structure createStructure() throws Exception {
ScriptingContainer container = new ScriptingContainer();
container.runScriptlet(PathType.CLASSPATH, "org/acme/app/scripts/dsl.rb");
// ...
}
And then this script requires other scripts:
puts __FILE__
require_relative 'drop_context'
This prints out "org/acme/app/scripts/dsl.rb" even though I would expect "classpath:/org/acme/app/scripts/dsl.rb", so require_relative is doomed to fail as the file is not on the filesystem (and indeed this does fail - it resolves the path relative to my home directory.)
I tried working around this by passing PathType.ABSOLUTE and "classpath:/org/.../dsl.rb" instead, but this doesn't work - ScriptingContainer loads this script directly, so it doesn't know that classpath is a special URL.
I'm not sure what the workaround is from here. I guess the worst case is that I accept that require_relative can't possibly work and use require with absolute paths.
Reactions are currently unavailable