Similar to this question, I’d like to know how to get the current jar file’s path. But unlike the other question, I want to know the jar‘s path, not the path of the current file inside the jar. For example, say I had a jruby jar at “/Users/MyUser/Jars/foo.jar” and inside was a compiled ruby file at “foo.jar/java/style/class/path.class”. How could class.path get the path “/Users/MyUser/Jars/foo.jar”?
I also saw a way to do it in Java, but I just don’t know how to translate it…
I have experimented with this a bit, and any attempt to call the code from JRuby returns the jruby jar itself, which kind of makes sense as the logic is indeed evaluated/executed from that jar. For instance:
or
both return the path to
jruby-complete.jar, which can be useful to some extent but apparently not what you’re looking for.The only way I could get this to work (with
rawr, but this can be easily adapted if you usewarbler) is to create a Java class insrc/java/org/rubyforge/rawr:Then call this class from the JRuby script: