2013-02-05 71 views
1

在Windows上使用Pry gem和JRuby和JRubyFx的正确方法是什么?Jruby:在JRuby(和JRubyFx)上使用Pry

我使用的JRubyFx(一个JavaFX的JRuby结合 - https://github.com/jruby/jrubyfx)和我的测试我使用这个example收缩到最小的必要线。

require 'jrubyfx' 
require 'pry' 

class SimpleFXApplication < JRubyFX::Application 
    def start(stage) 
    stage.title = "jrubyfx app" 
    @ctrlr = SimpleFXController.load_fxml("some_fxml_code_for_ui.fxml", stage) 
    stage.show 
    end 
end 

class SimpleFXController < JRubyFX::Controller 
end 

SimpleFXApplication.launch 
binding.pry 

启动应用程序,我的控制台不接受输入了与“撬”只回来接受输入当我关闭SimpleFXApplication窗口之后。

我用Java线程也尝试:

... 
binding.pry 
Java.java.lang.Thread.new do SimpleFXApplication.launch end 

不过,虽然新的线程ID显示为运行,SimpleFXApplication永远不会发生。

另一件事我试着开始从控制台撬,然后要求并启动SimpleFXApplication:

的JRuby -S撬

需要 './jrubyfx_demo.rb'

真正

SimpleFXApplication.launch

我收到以下错误...

异常运行的应用程序:java.net.MalformedURLException:未知 协议:C的java.net.URL(来源不明) 的java.net.URL(未知源) sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法) sun.reflect.NativeConstructorAccessorImpl.newInstance(来源不明) sun.reflect.DelegatingConstructorAccessorImpl.newInstance(未知 来源)java.lang.reflect.Constructor.newInstance(未知源) org.jruby.javasupport.JavaConstructor.newInstanceDirect(JavaConstructor.java:291) org .jruby.java.invokers.ConstructorInvoker.call(ConstructorInvoker.java:104) org.jruby.java.invokers.ConstructorInvoker.call(ConstructorInvoker.java:197) org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite .java:211) org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:217) org.jruby.java.proxies.ConcreteJavaProxy $ 2.call(ConcreteJavaProxy.java:56) org.jruby.runtime .callsite.CachingCallSite.callBlock(CachingCallSite.java:211) org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:217) org.jruby.RubyClass.newInstance(RubyClass.java:862) 有机jruby.RubyClass $ INVOKER $ i $ newInstance.call(RubyClass $ INVOKER $ i $ newInstance.gen) org.jruby.internal.runtime.methods.JavaMetho d $ JavaMethodZeroOrOneOrTwoOrNBlock.call(JavaMethod.java:295) org.jruby.java.proxies.ConcreteJavaProxy $ 3.call(ConcreteJavaProxy.java:155) org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:346 ) org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:204) org.jruby.ast.CallTwoArgNode.interpret(CallTwoArgNode.java:59) org.jruby.ast.NewlineNode.interpret(NewlineNode。的java:105) org.jruby.ast.BlockNode.interpret(BlockNode.java:71) org.jruby.ast.IfNode.interpret(IfNode.java:118) org.jruby.ast.AttrAssignOneArgNode.interpret(AttrAssignOneArgNode .java:33) org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105) org.jruby.ast.BlockNode.interpret(BlockNode.java:71) org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD( ASTInterpreter.java:75) org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:268) org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:220) 组织.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:366) org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSi te.java:238) org.jruby.ast.FCallThreeArgNode.interpret(FCallThreeArgNode.java:40) org.jruby.ast.LocalAsgnNode.interpret(LocalAsgnNode.java:123) org.jruby.ast.NewlineNode.interpret (NewlineNode.java:105) org.jruby.ast.BlockNode.interpret(BlockNode.java:71) org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75) org.jruby.internal.runtime。方法.InterpretedMethod.call(InterpretedMethod.java:225) org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:204) org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java: 346) org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:204) org.jruby.ast.CallTwoArgNode。解释(CallTwoArgNode.java:59) org.jruby.ast.InstAsgnNode.interpret(InstAsgnNode.java:95) org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105) org.jruby.ast.BlockNode org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:182) org。 jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:188) org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:326) org.jruby.runtime.callsite.CachingCallSite.call( CachingCallSite.java:170) org.jruby.ast.CallOneArgNode.interpret(CallOneArgNode.java:57) org.jruby.ast.New lineNode.interpret(NewlineNode.java:105) org.jruby.ast.BlockNode.interpret(BlockNode.java:71) org.jruby.ast.RescueNode.executeBody(RescueNode.java:224) org.jruby.ast .RescueNode.interpret(RescueNode.java:119) org.jruby.ast.BeginNode.interpret(BeginNode.java:83) org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105) org.jruby。 evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.java:112) org.jruby.runtime.Interpreted19Block.evalBlockBody(Interpreted19Block.java:209) org.jruby.runtime.Interpreted19Block.yield(Interpreted19Block.java:197) org.jruby .runtime.Interpreted19Block.call(Interpreted19Block.java:128) org.jruby.runtime.Block.call(Block.java:89) org.jruby.RubyProc.call(RubyProc.java:261) org.jruby.RubyProc.call(RubyProc.java:213) org.jruby.javasupport.JavaUtil $ 1.call(JavaUtil.java:237) 组织.jruby.javasupport.util.RuntimeHelpers $ MethodMissingMethod.call(RuntimeHelpers.java:445) org.jruby.gen.InterfaceImpl1014569521.run(org/jruby/gen/InterfaceImpl1014569521.gen:13) com.sun.javafx.application .PlatformImpl $ 5.run(PlatformImpl.java:215) com.sun.javafx.application.PlatformImpl $ 4 $ 1.run(PlatformImpl.java:179) com.sun.javafx.application.PlatformImpl $ 4 $ 1.run(PlatformImpl。 java:176) java.security.AccessController.doPrivileged(Native Method) com.sun.javafx.application.PlatformImpl $ 4.run(PlatformImpl.java:176) com。sun.glass.ui.win.WinApplication._runLoop(Native Method) com.sun.glass.ui.win.WinApplication.access $ 100(WinApplication.java:29) com.sun.glass.ui.win.WinApplication $ 3 $ 1.run(WinApplication.java:73) java.lang.Thread.run(来源不明) =>零

我猜测它有东西在JrubyFx如何使用线程做,或者我不t知道这是否是一个更普遍的问题,会影响JRuby的Pry使用情况。 我想知道更多,如果有人能分享一些建议,我将不胜感激。

+0

请显示您使用的代码。 –

+0

谢谢,我添加了代码并更好地描述了该问题。 –

+0

'some_fxml_code_for_ui.fxml'的完整路径是什么? –

回答

2

SimpleFXApplication.launch永远不会返回,直到Platform.exit被称为(关闭车窗做到这一点的背景)

做你正在尝试到,在启动方法叉掉,或者在其他一些定时器方法一旦JavaFX启动应用程序。

作为的JRubyFX开发商之一,我也可以告诉你如何在JRubyFX/JavaFX的线程工作:

  1. 主线程派生的UI JavaFX的线程,并等待从JavaFX的螺纹
  2. UI锁螺纹推出一堆东西平台
  3. UI线程调用启动(阶段)
  4. 开始(第一阶段)设置事件处理程序,用户界面等(这是你应该启动撬)
  5. 用户通话stage.show到启动JavaFX事件(单击,鼠标移动,按键,最小化等)
  6. 事件线程回调到UI线程与事件处理程序
  7. 用户信号通过单击[x]或调用Platform.exit他们要关闭JavaFX
  8. stage.show接收事件锁并返回
  9. UI线程释放锁定主线程。
  10. UI线程清理而主线程继续
0

对此:

异常运行的应用程序:java.net.MalformedURLException:未知协议:C的java.net.URL(未知来源)的java。 net.URL。(Unknown Source)

你的配置文件中是否有指定文件位置的内容?如果是这样,那里的价值是多少?

如果你正在使用“C:[something]”,并且C是你当前的驱动器,我会建议尝试删除“C:”以防撬由驱动器号弄糊涂。

- Keith