当前位置: 首页 > 工具软件 > Ruby FFI > 使用案例 >

java调用ruby_使用 java 调用 ruby 脚本的办法??

宗政招
2023-12-01

最近做了一个脚本。

后来又用 java 做了个界面。想用 java 调用脚本。

直接使用 ruby 脚本没有问题,再用 java 调用 ruby 脚本之后就出现问题了。

现在出现的问题是:

1.有好几个 ruby 文件。 java 调用其中一个文件 a.rb 后, a.rb 中 require 的 b.rb 就查找不到路径了,即时再同一个目录下

2.比如调用了本地的 pod , a.rb 中有 require 'pod',结果也找不到 pod 。

脚本的开头部分:

require 'json'

require 'xcodeproj'

$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'custom_add_system_framework.rb'

require 'LaunchImage.rb'

错误信息如下:

LoadError: no such file to load -- xcodeproj

require at org/jruby/RubyKernel.java:939

require at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:54

at

javax.script.ScriptException: org.jruby.embed.EvalFailedException: (LoadError) no such file to load -- xcodeproj

at org.jruby.embed.jsr223.JRubyEngine.wrapException(JRubyEngine.java:104)

at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:121)

at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:146)

at org.springframework.richclient.sample.utils.IosPackectTools.packTools(IosPackectTools.java:25)

at org.springframework.richclient.sample.form.PackPathJFrame$3.actionPerformed(PackPathJFrame.java:155)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)

at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)

at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)

at java.awt.Component.processMouseEvent(Component.java:6525)

at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)

at java.awt.Component.processEvent(Component.java:6290)

at java.awt.Container.processEvent(Container.java:2234)

at java.awt.Component.dispatchEventImpl(Component.java:4881)

at java.awt.Container.dispatchEventImpl(Container.java:2292)

at java.awt.Component.dispatchEvent(Component.java:4703)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)

at java.awt.Container.dispatchEventImpl(Container.java:2278)

at java.awt.Window.dispatchEventImpl(Window.java:2750)

at java.awt.Component.dispatchEvent(Component.java:4703)

at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)

at java.awt.EventQueue.access$500(EventQueue.java:97)

at java.awt.EventQueue$3.run(EventQueue.java:709)

at java.awt.EventQueue$3.run(EventQueue.java:703)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)

at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)

at java.awt.EventQueue$4.run(EventQueue.java:731)

at java.awt.EventQueue$4.run(EventQueue.java:729)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Caused by: org.jruby.embed.EvalFailedException: (LoadError) no such file to load -- xcodeproj

at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:131)

at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:118)

... 40 more

Caused by: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- xcodeproj

at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:939)

at uri_3a_classloader_3a_.META_minus_INF.jruby_dot_home.lib.ruby.stdlib.rubygems.core_ext.kernel_require.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:54)

at RUBY.(

请问有过类似经验的同志们帮忙解决一下。

实在找不到解决办法了。

谷歌了半天也没什么结果。

 类似资料: