我在 Windows 中从 mingw git bash shell 执行 jruby 时遇到问题。我下载了 jruby 1.6.2 的 Windows 安装程序并运行它没有问题。如果我打开一个新的 Windows cmd shell,它似乎工作正常。我安装了 rake 和 sinatra gems;使用了irb。输入 jruby -v 获取:
jruby 1.6.2 (ruby-1.8.7-p330) (2011-05-23 e2ea975) (Java HotSpot(TM) Client VM 1.6.0_24) [Windows 7-x86-java]
但是,当我打开 git mingw bash shell 并尝试对 jruby 执行任何操作时,我收到此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jruby/Main
Caused by: java.lang.ClassNotFoundException: org.jruby.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: org.jruby.Main. Program will exit.
我已确保 jruby lib 目录位于类路径中。
还有其他想法吗?
更新:
我认为问题在于 shell 脚本最终调用 jruby bin 目录中的 jar。
问题是,虽然 msys 可以将 POSIX 转换为 Win 路径,但该脚本会自行构建字符串,以便将类路径和其他信息传递给 jar。
看来这就是事情变得混乱的地方。出于同样的原因,这些脚本特别具有处理 cygwin 的代码分支。我试图强制脚本认为它是在 cygwin 下运行,但不幸的是,脚本使用“cygpath”程序来获取路径,而这在 msys 中不可用
I'm having an issue executing jruby from the mingw git bash shell in windows. I downloaded the windows installer for jruby 1.6.2 and ran it without issue. If I open a new windows cmd shell it seems to work fine. I installed the rake and sinatra gems; used the irb. entering jruby -v gets:
jruby 1.6.2 (ruby-1.8.7-p330) (2011-05-23 e2ea975) (Java HotSpot(TM) Client VM 1.6.0_24) [Windows 7-x86-java]
However, when I open the git mingw bash shell and attempt to do anything with jruby I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jruby/Main
Caused by: java.lang.ClassNotFoundException: org.jruby.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: org.jruby.Main. Program will exit.
I have made sure that the jruby lib directory is in the classpath.
Any other ideas?
UPDATE:
I think the issue is the shell scripts that end up invoking the jar in the jruby bin directory.
The issue is that while msys can transform POSIX to Win paths for most things, but the script builds up strings on its own in order to pass classpath and other information to the jar.
It appears that this is where things are getting messed up. The scripts specifically have branches of code that deal with cygwin for this same reason. I attempted to force the scripts to to think that it was running under cygwin but unfortunately the scripts make use of the "cygpath" program to get the paths and that is not available in msys
发布评论
评论(2)
事实证明这确实是 bash 脚本的“缺失功能”。我向 jruby jira 提交了一个错误,并已解决
https://jira.codehaus.org/browse /JRUBY-5864
请注意,截至撰写本文时,该提交尚未成为可在 jruby 网站上下载的构建的一部分。但修复方法非常简单。
这是提交: https://github.com/jruby/jruby/commit/8766f84b774ae5ae68204931bd4eab61b81a2056
就是将以下内容添加到 jruby.bash 文件顶部的 uname 大小写中
Turns out is was indeed a "missing feature" of the bash scripts. I submitted a bug to the jruby jira and it was resolved
https://jira.codehaus.org/browse/JRUBY-5864
Note that as of the time of this writing that commit has not been part of the build that's available for download on the jruby web site. But the fix was quite simple.
Here is the commit: https://github.com/jruby/jruby/commit/8766f84b774ae5ae68204931bd4eab61b81a2056
All it is is adding the following to the uname case at the top of the jruby.bash file
诀窍是,mingw shell 可能不会从 Windows 环境继承所有环境变量。
因此,如果
java -jar lib/jruby.jar -e "puts 'hello
在 jruby 目录中工作,那么:也应该工作。
如果没有,请仔细比较两组环境变量(正常的 DOS shell,它可以工作,而 mingw shell,它不能工作)。
它也可以像 mingw 环境中类路径的语法差异,如 在此线程中说明:
The trick is, a mingw shell might not inherit all environment variables from the Windows environment.
So if a
java -jar lib/jruby.jar -e "puts 'hello
works within the jruby directory, then:ought to work as well.
If not, carefully diff the two set of environment variables (normal DOS shell, where it works, and mingw shell where it doesn't)
It could also be as simple as a difference of syntax for the classpath in a mingw environment, as illustrated in this thread: