编译jruby“Hello world”问题 [英] Compile jruby "Hello world" problem

查看:184
本文介绍了编译jruby“Hello world”问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Ruby编程了一段时间,我真的很喜欢它。最近我开始需要编译一些ruby代码。由于几个原因使用Ruby2exe不是一个选择我。所以我决定给Jruby一个尝试(生成一个jar将是足够好的)。



我使用windows和我安装java JDK 6u17(在C:\Program














$ b p>

我创建了一个文件script.rb与:

我创建了一个hello世界在java,编译和执行它只是罚款/ p>

放置Hello,world



这个程序与jruby:



jruby script.rb



我已将JAVA_HOME设置为C:\Program Files\Java\jdk1.6.0_17



我也成功运行:



java -jar c:\jruby\lib\jruby.jar .rb



然后用命令编译:



jruby -S jrubyc script.rb



它会生成类'script.class'



我的问题是我没有办法正确执行script.class



我尝试:



java -cp::c:\jruby\lib\jruby.jar script



我得到错误消息:

 线程main中的异常java.lang.NoClassDefFoundError:script 
Caused by: java.lang.ClassNotFoundException:script
在java.net.URLClassLoader $ 1.run(未知源)
在java.security.AccessController.doPrivileged(本地方法)
在java.net.URLClassLoader .findClass(未知源)
at java.lang.ClassLoader.loadClass(未知源)
at sun.misc.Launcher $ AppClassLoader.loadClass(未知源)
at java.lang.ClassLoader .loadClass(未知源)
at java.lang.ClassLoader.loadClassInternal(未知源)
找不到主类:script。程序将退出。

我也试过将jruby-complete-1.4.0.jar复制到本地dir以及其他几个



任何人都知道我做错了什么?

解决方案

假设你在windows上,我认为你的-cp参数是错误的:它应该是分号分隔:



java -cp。 :\jruby\lib\jruby.jar script



但是,我通过单独设置CLASSPATH env更好的运气,例如:

  
C:\ruby> set CLASSPATH = c:\Program Files\jruby- 0\lib\jruby.jar;

C:\ruby> java hello_world
你好,世界!

但也许这是因为我的类路径需要一个空格。



您使用的是什么版本的JRuby?正如你所看到的,我在1.4。


I have been programming for a while with Ruby and I really enjoy it. Lately I started having the need of compiling some ruby code. For several reasons using Ruby2exe is not an option for me. So I decided to give Jruby a try (generating a jar would be good enough).

I am using windows and I installed java JDK 6u17 (at C:\Program Files\Java\jdk1.6.0_17).

I installed jruby 1.4 at C:\jruby

I created a hello world in java, compile and executed it just fine (so java works fine).

I created a file "script.rb" with:

puts "Hello, world"

I run this program with jruby:

jruby script.rb

And it works fine.

I did set JAVA_HOME to C:\Program Files\Java\jdk1.6.0_17

I also successfully run:

java -jar c:\jruby\lib\jruby.jar script.rb

I then compile with the command:

jruby -S jrubyc script.rb

It generates the class 'script.class'

My problem is that I found no way to properly execute script.class

I try:

java -cp .:c:\jruby\lib\jruby.jar script

And I get the error message:

Exception in thread "main" java.lang.NoClassDefFoundError: script
Caused by: java.lang.ClassNotFoundException: script
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: script.  Program will exit.

I also tried copying jruby-complete-1.4.0.jar to local dir as well as several other options.

Anyone know what am I doing wrong?

解决方案

Assuming you are on windows, I think your -cp arg is wrong: it should be semi-colon delimited:

java -cp .;c:\jruby\lib\jruby.jar script

But also, I had better luck by setting the CLASSPATH env separately, e.g.:


C:\ruby>set CLASSPATH=c:\Program Files\jruby-1.4.0\lib\jruby.jar;

C:\ruby>java hello_world
Hello, world!

But perhaps that's because my classpath needs a space in it.

What version of JRuby are you using? As you can see, I'm on 1.4.

这篇关于编译jruby“Hello world”问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆