0

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?

4

1 回答 1

0

核心/lib/gui.rb

puts "core was loaded!"

我将 Ruby 代码(不使用 Warbler 或类似的东西)打包为jar -cf core.jar core.

主.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'");
    }
}

编译为javac -cp jruby-1.7.9.jar Main.java -d build

跑步

然后我能够将此代码作为java -cp jruby-1.7.9.jar:build/ Main.

于 2013-12-30T15:55:12.043 回答