[英]org.jruby.embed.EvalFailedException: (LoadError) no such file to load
I've created jar file from ruby code using warbler. 我已经使用莺根据红宝石代码创建了jar文件。 File structure within jar is as below:
jar中的文件结构如下:
core.jar core.jar
----core - - 核心
--------lib -------- lib
------------gui.class ------------ gui.class
------------gui.rb ------------ gui.rb
I've other java application from which I want to run "connect" function which is in Gui class of gui.rb. 我还有另一个Java应用程序,我想从中运行gui.rb的Gui类中的“ connect”功能。
I've tried below code in java: 我试过下面的代码在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". 上面代码的最后一行给了我一个例外:“ LoadError:没有要加载的此类文件-gui”。 How can I call the function of gui.rb?
如何调用gui.rb函数?
core/lib/gui.rb 核心/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
. 我将Ruby代码(不使用Warbler或类似的东西)
jar -cf core.jar core
为jar -cf core.jar core
。
Main.java 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
编译为
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
. 然后,我能够以
java -cp jruby-1.7.9.jar:build/ Main
身份运行此代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.