JRuby Warbler没有创建可用的可执行JAR文件

时间:2014-04-08 20:40:51

标签: java ruby jruby bundler warbler

我一直试图获得一个非常简单的JRuby脚本,它需要Net :: SSH在远程计算机上执行任务并退出。当我发出命令jruby testssh.rb时,程序运行完美,但是,当我使用Warbler将其编译成JAR时,我收到有关无法加载Net :: SSH的错误。

> java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

> pik use jruby-1.7.1

> jruby -S warble jar
C:/ruby/jruby-1.7.10/lib/ruby/gems/shared/gems/rawr-1.7.0/lib/zip/zip.rb:28: Use RbConfig instead of obsolete and deprecated Config.
rm -f test-ssh.jar
Creating test-ssh.jar

> java -jar test-ssh.jar
LoadError: no such file to load -- net/ssh
  require at org/jruby/RubyKernel.java:1085
  require at file:/C:/Users/User/AppData/Local/Temp/jruby4935218336857439685extract/jruby-stdlib-complete-1.7.11.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:55
   (root) at test-ssh.rb:7
     load at org/jruby/RubyKernel.java:1101
   (root) at file:/C:/Users/User/Dropbox/programming/ruby/jruby/net-ssh/test-ssh/test-ssh.jar!/META-INF/main.rb:1
  require at org/jruby/RubyKernel.java:1085
   (root) at file:/C:/Users/User/AppData/Local/Temp/jruby4935218336857439685extract/jruby-stdlib-complete-1.7.11.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
  require at file:/C:/Users/User/AppData/Local/Temp/jruby4935218336857439685extract/jruby-stdlib-complete-1.7.11.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:55
error: org.jruby.embed.EvalFailedException: (LoadError) no such file to load -- net/ssh

然后我将文件放入gem中,并将spec.add_runtime_dependency = "net-ssh"添加到gemspec中,并且:

require 'net/ssh'
gem "net-ssh"

进入Gemfile。然后当我运行jruby -S warble时,我得到一个不同的错误。我也注意到,Bundler和Ruby并没有很好地发挥' - '在名称中,所以我不得不重新创建该文件。

> jruby -S warble
C:/ruby/jruby-1.7.10/lib/ruby/gems/shared/gems/rawr-1.7.0/lib/zip/zip.rb:28: Use RbConfig instead of obsolete and deprecated Config.
No default executable found in test-ssh.gemspec, using bin/test-ssh.rb
rm -f test-ssh.jar
Creating test-ssh.jar

> java -jar testssh.jar
LoadError: no such file to load -- testssh/bin/testssh.rb
     load at org/jruby/RubyKernel.java:1101
   (root) at file:/C:/Users/User/Dropbox/programming/ruby/jruby/net-ssh/testssh/testssh.jar!/META-INF/main.rb:1
  require at org/jruby/RubyKernel.java:1085
   (root) at file:/C:/Users/User/AppData/Local/Temp/jruby6762643836642223701extract/jruby-stdlib-complete-1.7.11.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
  require at file:/C:/Users/User/AppData/Local/Temp/jruby6762643836642223701extract/jruby-stdlib-complete-1.7.11.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:55
error: org.jruby.embed.EvalFailedException: (LoadError) no such file to load -- testssh/bin/testssh.rb

我因为需要做什么而感到茫然,而且我发现很多关于类似问题的半生不熟的答案,或者在Warbler github上留下了关于此问题的人页面超过一年没有答案。

代码和错误的要点位于:https://gist.github.com/predatorian3/10191754


解决方案是:

bundler创建Ruby gem的方式是它使用Git,我没有使用git add .来包含所有已更改的目录。在我git add .git commit完成后,Warbler选择了第一个错过的目录。然后对于gem依赖,它就像编辑.gemspec文件一样简单,并为我自己的gem中需要的每个gem包含runtime_dependency。之后,Warbler包含了这些依赖项,并且JAR文件可以在没有安装JRuby的情况下运行。

1 个答案:

答案 0 :(得分:1)

运行jar时需要一些可以运行的文件!您可以在gemspec中指定一个,但默认为bin / .rb。没有这样的文件,因此错误。