Here i am trying to load my Jruby script into my java code but am getting long error that i realy don’t know what it means,
The player.rb file is in the same folder as the TEST.java is.
Here is the error am getting:
java.io.FileNotFoundException: .player.rb (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.io.FileInputStream.<init>(FileInputStream.java:79)
at org.jruby.embed.internal.EmbedRubyRuntimeAdapterImpl.parse(EmbedRubyRuntimeAdapterImpl.java:117)
at org.jruby.embed.ScriptingContainer.parse(ScriptingContainer.java:1195)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1275)
at test.TEST.<init>(TEST.java:29)
at test.TEST.main(TEST.java:33)
Exception in thread "main" org.jruby.embed.ParseFailedException: java.io.FileNotFoundException: .player.rb (The system cannot find the file specified)
at org.jruby.embed.internal.EmbedRubyRuntimeAdapterImpl.parse(EmbedRubyRuntimeAdapterImpl.java:143)
at org.jruby.embed.ScriptingContainer.parse(ScriptingContainer.java:1195)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1275)
at test.TEST.<init>(TEST.java:29)
at test.TEST.main(TEST.java:33)
Caused by: java.io.FileNotFoundException: .player.rb (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.io.FileInputStream.<init>(FileInputStream.java:79)
at org.jruby.embed.internal.EmbedRubyRuntimeAdapterImpl.parse(EmbedRubyRuntimeAdapterImpl.java:117)
... 4 more
Java Result: 1
Here is my Java code:
import org.jruby.*;
import java.util.ArrayList;
import java.util.List;
import org.jruby.embed.PathType;
import org.jruby.embed.ScriptingContainer;
public class TEST {
private final static String jrubyhome = "C:/jruby-1.6.3";
private final String filename = "player.rb";
private TEST() {
ScriptingContainer container = new ScriptingContainer();
List<String> loadPaths = new ArrayList();
loadPaths.add(jrubyhome);
// JRuby 1.5.x
container.setLoadPaths(loadPaths);
// JRuby 1.4.0
//container.getProvider().setLoadPaths(loadPaths);
container.runScriptlet(PathType.ABSOLUTE, filename);
}
public static void main(String[] args) {
new TEST();
}
}
And here is my Ruby code:
def numberMethod
number = 3
return number
end
puts numberMethod
puts "Test, test!"
The new error i got now:
java.io.FileNotFoundException: C:\Users\Oskar\Documents\NetBeansProjects\TEST\src\test (Access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:120)
at java.io.FileInputStream.(FileInputStream.java:79)
at org.jruby.embed.internal.EmbedRubyRuntimeAdapterImpl.parse(EmbedRubyRuntimeAdapterImpl.java:117)
at org.jruby.embed.ScriptingContainer.parse(ScriptingContainer.java:1195)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1275)
at test.TEST.(TEST.java:29)
at test.TEST.main(TEST.java:33)
Exception in thread “main” org.jruby.embed.ParseFailedException: java.io.FileNotFoundException: C:\Users\Oskar\Documents\NetBeansProjects\TEST\src\test (Access is denied)
at org.jruby.embed.internal.EmbedRubyRuntimeAdapterImpl.parse(EmbedRubyRuntimeAdapterImpl.java:143)
at org.jruby.embed.ScriptingContainer.parse(ScriptingContainer.java:1195)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1275)
at test.TEST.(TEST.java:29)
at test.TEST.main(TEST.java:33)
Caused by: java.io.FileNotFoundException: C:\Users\Oskar\Documents\NetBeansProjects\TEST\src\test (Access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:120)
at java.io.FileInputStream.(FileInputStream.java:79)
at org.jruby.embed.internal.EmbedRubyRuntimeAdapterImpl.parse(EmbedRubyRuntimeAdapterImpl.java:117)
… 4 more
Java Result: 1
The new java code:
import org.jruby.*;
import java.util.ArrayList;
import java.util.List;
import org.jruby.embed.PathType;
import org.jruby.embed.ScriptingContainer;
public class TEST {
private final static String jrubyhome = "C:/jruby-1.6.3";
private final String filename = "C:/Users/Oskar/Documents/NetBeansProjects/TEST/src/test/player.rb";
private TEST() {
ScriptingContainer container = new ScriptingContainer();
List<String> loadPaths = new ArrayList();
loadPaths.add(jrubyhome);
// JRuby 1.5.x
container.setLoadPaths(loadPaths);
// JRuby 1.4.0
//container.getProvider().setLoadPaths(loadPaths);
container.runScriptlet(PathType.RELATIVE, filename);
}
public static void main(String[] args) {
new TEST();
}
}
I guess the
PathType.ABSOLUTEconstant is the culprit. Change that (e.g. toPathType.RELATIVE) or provide the full path to yourtest.rbfile.