Question

I use jrubyc to compile Ruby into class files. One of the Ruby files contains

dat = File.open "data.json", "r"

And there's a "data.json" file alongside. This program runs well if I directly use the jruby command.

After I compiled the Ruby files and put them into a jar, the following error appears when I run java -jar:

Exception in thread "main" org.jruby.exceptions.RaiseException: (Errno::ENOENT) data.json
at org.jruby.RubyFile.initialize(org/jruby/RubyFile.java:334)
at org.jruby.RubyIO.open(org/jruby/RubyIO.java:1144)
at RUBY.(root)(file:/Users/x5lai/Documents/rqrcode.jar!/read.rb:2)
...

To make sure that I have not put data.json in the wrong place, I have copied data.json all over the jar file, but the same error occurs.

Is there anyway to do this? Is JRuby unable to open JSON files once I have compiled the code?

Was it helpful?

Solution

I don't think that it is going to look inside the JAR by default. I created a small test and was able to reproduce your issue. I then did touch data.json and the code no longer had an error. I'm not sure how to specify that you want to look inside the JAR for your data file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top