简体   繁体   中英

org.jruby.embed.EvalFailedException: (LoadError) no such file to load

I've created jar file from ruby code using warbler. File structure within jar is as below:

core.jar
----core
--------lib
------------gui.class
------------gui.rb

I've other java application from which I want to run "connect" function which is in Gui class of gui.rb.

I've tried below code in java:

ScriptingContainer SCRIPTING_CONTAINER = new ScriptingContainer;
// String CORE_JAR_PATH = "core.jar";
String CORE_JAR_PATH = "core.jar!/core/lib";
SCRIPTING_CONTAINER.getLoadPaths().add(CORE_JAR_PATH);
SCRIPTING_CONTAINER.runScriptlet("require 'gui'");

The last line in above code is giving me the exception "LoadError: no such file to load -- gui". How can I call the function of gui.rb?

core/lib/gui.rb

puts "core was loaded!"

I packed the Ruby code (not using Warbler or anything like that) as jar -cf core.jar core .

Main.java

import org.jruby.embed.ScriptingContainer;

public class Main {
    public static void main(String[] args) {
        ScriptingContainer container = new ScriptingContainer();
        container.runScriptlet("require './core.jar'");
        container.runScriptlet("require 'core/lib/gui'");
    }
}

Compiled as javac -cp jruby-1.7.9.jar Main.java -d build

Running

I was then able to run this code as java -cp jruby-1.7.9.jar:build/ Main .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM